irwan

Generate secure passwords.

Apr 18th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?PHP
  2. // selection of possible character
  3. $letters = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
  4. $numbers = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
  5. $special = array("!", "&", "=", "?");
  6. $length = 8;
  7.  
  8. // Generate secure passwords
  9. $password = "";
  10. for($i=0; strlen($password)<$length; $i++){
  11.  $random = mt_rand(1,100);
  12.  if($random < 50)
  13.   {$password.=$letters[mt_rand(0, count($letters)-1)];}
  14.  elseif($random > 60)
  15.   {$password.=$numbers[mt_rand(0, count($numbers)-1)];}
  16.  else
  17.   {$password.=$special[mt_rand(0, count($special)-1)];}
  18. }
  19. // output
  20. echo "Password: $password";
  21. ?>
Add Comment
Please, Sign In to add comment