Password Function


/ Published in: PHP
Save to your folder(s)

Generate random plain and md5 password. Depend on Password Class


Copy this code and paste it in your HTML
  1. private function genPassword() {
  2. //Generate password
  3. $letter = array("a", "b", "c", "d", "e", "f", "g", "h", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
  4. $numbers = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
  5. $specialCharacters = array("#", "!", "%");
  6. $lenght = 8;
  7.  
  8. for($i=0, $password=""; strlen($password)<$lenght; $i++)
  9. {
  10. if(rand(0, 2)==0 && isset($letter))
  11. {
  12. $password.=$letter[rand(0, count($letter))];
  13. }
  14. elseif(rand(0, 2)==1 && isset($numbers))
  15. {
  16. $password.=$numbers[rand(0, count($numbers))];
  17. }
  18. elseif(rand(0, 2)==2 && isset($specialCharacters))
  19. {
  20. $password.=$specialCharacters[rand(0, count($specialCharacters))];
  21. }
  22. }
  23.  
  24.  
  25.  
  26. $md5Hash = md5($password);
  27. // Create object for further use. Depend on Password Class
  28. $oPassword = new Password('',$md5Hash,$password);
  29. return $oPassword;
  30. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.