jwk811 Posted November 15, 2006 Share Posted November 15, 2006 im using this little random password generator this is its code - [code] function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } [/code]see where it says $pass = $pass . $tmp;? well where is it getting the $pass inside the variable? im getting an error saying undefined variable but the code is still working perfectly.. and when i get rid of the $pass it messes up and doesnt work... crazy huh? would you know whats wrong with this? this is actually something i found at this website and its working on some of my other script but not this one.. dont understand.. thanks for help! Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 15, 2006 Share Posted November 15, 2006 The first time through, concatenate a null string and a random string. Then the second time, it's got the value of the previous run. It' works on SOME servers because the error reporting settings are lower on some servers.it could be fixed (causing no errors) by adding $pass = ""; above the start of the while loop.That way it wouldn't be a NULL string. Quote Link to comment Share on other sites More sharing options...
jsladek Posted November 15, 2006 Share Posted November 15, 2006 I've used this before, forget where I found it but it looks very similar to your code. I did not get any errors when I used it. It's also commented, which is nice.[code]function generatePassword ($length = 8){ // start with a blank password $password = ""; // define possible characters $possible = "0123456789bcdfghjkmnpqrstvwxyz"; // set up a counter $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($password, $char)) { $password .= $char; $i++; } } // done! return $password;}[/code]Regards,John Sladek Quote Link to comment Share on other sites More sharing options...
jwk811 Posted November 15, 2006 Author Share Posted November 15, 2006 great thanks! it was because the null thing.. and thanks for the code john! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.