Posted By

iTony on 12/12/08


Tagged

php password php5 reandom


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

rickfu
brent-man
jackii
baqc
vali29
catrinho


Generate Random Password


 / Published in: PHP
 

  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  

Comments

RSS Icon Subscribe to comments
Posted By: bAxTEr on March 30, 2009

Is very nice this function

thank u

You need to login to post a comment.