Posted By

fruehjahr on 01/05/09


Tagged

password random security


Versions (?)

Who likes this?

10 people have marked this snippet as a favorite

jonas3344
jfherring
Scooter
will_00
luman
umang_nine
pezland
Hollow
vali29
rmethod


Random password generator


 / Published in: PHP
 

URL: http://www.webtoolkit.info/php-random-password-generator.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. $consonants .= '@#$%';
  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. }

Report this snippet  

You need to login to post a comment.