Posted By

cshaiku on 06/30/09


Tagged

password random


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

cshaiku
rickfu
vali29


Password Generator


 / Published in: PHP
 

URL: http://code.cshaiku.com/code_php_password_generator.php

  1. function randomStr($length) {
  2. $randomStr = "";
  3. $chars = array('2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
  4. while(strlen($randomStr) < $length) {
  5. $alt = rand(1,2) % 2;
  6. if (0 == $alt)
  7. $randomStr .= strtoupper($chars[rand(0, count($chars) - 1)]);
  8. else
  9. $randomStr .= $chars[rand(0, count($chars) - 1)];
  10. }
  11. return $randomStr;
  12. }
  13.  
  14. $len = (int) 8; // 1 trillion+ is enough doncha think?
  15.  
  16. if (@strlen($_GET['len']) > 0) {
  17. if (strlen($_GET['len']) > 2)
  18. header('Location:./' . substr(urldecode(addslashes($_GET['len'])), 0, 2));
  19. $len = (int) substr(urldecode(addslashes($_GET['len'])), 0, 2);
  20. }
  21.  
  22. $password = randomStr($len);

Report this snippet  

You need to login to post a comment.