19
Jul
Random generated password
Posted by Hussain, under PHPMany time in registration page or forgotten password, the new password should be generated to sent. This code will help to generate random password.
| PHP | | copy code | | ? |
| 01 | /** |
| 02 | * Function to generate random password |
| 03 | * @param $length length of password require |
| 04 | */ |
| 05 | |
| 06 | |
| 07 | function getPassword($length) |
| 08 | { |
| 09 | srand(date("s")); |
| 10 | $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
| 11 | $string = ""; |
| 12 | while(strlen($string)<$length) { |
| 13 | $string .= substr($possible_charactors, rand()%(strlen($possible_charactors)),1); |
| 14 | } |
| 15 | return($string); |
| 16 | } |
| 17 |



Post a Comment