/ Published in: PHP
Expand |
Embed | Plain Text
#!/usr/bin/php <?php /** * Generate a random password */ class Password { /** * Generate the new password * * @access public * @param array $params * @return string **/ { $upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $lower = "abcdefghijklmnopqrstuvwxyz"; $number = "0123456789"; $seed_length = 0; $seed = ''; $password = ''; if($use_upper === TRUE){ $seed_length += 26; $seed .= $upper; } if($use_lower === TRUE){ $seed_length += 26; $seed .= $lower; } if($use_number === TRUE){ $seed_length += 10; $seed .= $number; } $seed .= $use_custom; } for($i = 1; $i <= $length; $i++){ } return $password; } // End of generate } // End of Class Password // ------------------------------------------------------------------------ /** * With Special Characters **/ echo "\nWith Special Characters: \n"; echo "-------------------------\n"; $password = new Password; for ($i=10; $i <= 80; $i += 10) { $password = new Password; } // ------------------------------------------------------------------------ /** * Without Special Characters **/ echo "\nWithout Special Characters: \n"; echo "----------------------------\n"; $password = new Password; for ($i=10; $i <= 80; $i += 10) { $password = new Password; } // ------------------------------------------------------------------------ /** * SHA1 Based * These passwords will only contain lowercase letters from a to f and numbers from 0 to 9 **/ echo "\nSHA1 Based: \n"; echo "------------\n"; echo "40: ${hash1}\n"; echo "80: ${hash2}\n";
Comments
Subscribe to comments
You need to login to post a comment.

Line 149 replace this : $password .= $seed{rand(0,$seed_length-1)};
By this : $password .= $seed{rand(0,$seed_length-1)};
Otherwise it throws an undefined $password var
By this : $password = $seed{rand(0,$seed_length-1)};
benoit: The code I posted works perfectly for me. Do not, I repeat do not replace $password .= $seed{rand(0,$seedlength-1)}; by $password = $seed{rand(0,$seedlength-1)}; or else the paswords generated will only be one character long. What you could do is add the following code on line 31: $password = ''; That should solve your problem.
I updated the snippet, now you shouldn't have a problem.