On Mon, 2004-04-26 at 11:28, Jonathan Viney wrote: > Hi all, > > Can someone tell me how I can generate a password which could be used in > the pw_passwd field in MySQL? > > If possible, I'd like MySQL to generate the password, can anyone give me > some pointers? > > Cheers, > Jonathan
Hi, I don't know if this will really help you, but that's what I use to generate passwords from php. $clearpass = "something"; $crypted = ''; if (mkpasswd3($clearpass, $crypted)) { printf("%s -> %s\n",$clearpass, $crypted); } else echo("Failed to create password"); function randltr() { $retval = 'a'; $rand = rand() % 64; if ($rand < 26) $retval = $rand + 'a'; if ($rand > 25) $retval = $rand - 26 + 'A'; if ($rand > 51) $retval = $rand - 52 + '0'; if ($rand == 62) $retval = ';'; if ($rand == 63) $retval = '.'; return($retval); } function mkpasswd3(&$clearpass, &$crypted) { srand ((double)microtime()*1000000); $salt = '$1$'; for ($i = 0; $i < 5; $i++) $salt .= randltr(); $salt .= '0'; $crypted = crypt($clearpass, $salt); if (strlen($crypted) > 0) return(true); return(false); }