Generate a password in php


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



Copy this code and paste it in your HTML
  1. function generatePassword($length=9, $strength=0) {
  2. $vowels = 'aeuy';
  3. $consonants = 'bdghjmnpqrstvz';
  4. if ($strength >= 1) {
  5. $consonants .= 'BDGHJLMNPQRSTVWXZ';
  6. }
  7. if ($strength >= 2) {
  8. $vowels .= "AEUY";
  9. }
  10. if ($strength >= 4) {
  11. $consonants .= '23456789';
  12. }
  13. if ($strength >= 8 ) {
  14. $vowels .= '@#$%';
  15. }
  16.  
  17. $password = '';
  18. $alt = time() % 2;
  19. for ($i = 0; $i < $length; $i++) {
  20. if ($alt == 1) {
  21. $password .= $consonants[(rand() % strlen($consonants))];
  22. $alt = 0;
  23. } else {
  24. $password .= $vowels[(rand() % strlen($vowels))];
  25. $alt = 1;
  26. }
  27. }
  28. return $password;
  29. }

URL: http://www.phpsnippets.info/generate-a-password-in-php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.