https://github.com/webmin/webmin/issues#issue/9
# Generate password if needed
if ($in{'new'} && $mconfig{'random_password'}) {
- &seed_random();
- foreach (1 .. 15) {
- $random_password .= $random_password_chars[
- rand(scalar(@random_password_chars))];
- }
+ $random_password = &useradmin::generate_random_password();
}
# Check if temporary locking is supported
# Get the password, generate random if needed
$pass = $n ne "" ? $uinfo{'pass'} : $config{'lock_string'};
if ($n eq "" && $config{'random_password'}) {
- &seed_random();
- foreach (1 .. 15) {
- $random_password .= $random_password_chars[
- rand(scalar(@random_password_chars))];
- }
+ $random_password = &generate_random_password();
}
# Check if temporary locking is supported
&my_endpwent();
}
+=head2 generate_random_password()
+
+Returns a randomly generated 15 character password
+
+=cut
+sub generate_random_password
+{
+&seed_random();
+my $rv;
+foreach (1 .. 15) {
+ $rv .= $random_password_chars[rand(scalar(@random_password_chars))];
+ }
+return $rv;
+}
+
1;