re-factor random password generation function, use in LDAP module
authorJamie Cameron <jcameron@webmin.com>
Tue, 16 Nov 2010 19:07:38 +0000 (11:07 -0800)
committerJamie Cameron <jcameron@webmin.com>
Tue, 16 Nov 2010 19:07:38 +0000 (11:07 -0800)
https://github.com/webmin/webmin/issues#issue/9

ldap-useradmin/edit_user.cgi
useradmin/edit_user.cgi
useradmin/user-lib.pl

index 3a5ab8e..aff751a 100755 (executable)
@@ -173,11 +173,7 @@ print &ui_table_row($text{'shell'},
 
 # 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
index 0ac1888..0a66466 100755 (executable)
@@ -165,11 +165,7 @@ print &ui_table_row(&hlink($text{'shell'}, "shell"),
 # 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
index e6399e7..554b779 100755 (executable)
@@ -2602,4 +2602,19 @@ while(my @uinfo = &my_getpwent()) {
 &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;