Advertisement
dakrizzz

[Php] Generate Random PWD

Jan 1st, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. //Original Source: http://stackoverflow.com/questions/6101956/generating-a-random-password-in-php
  2.  
  3. function randomPassword() {
  4.     $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
  5.     $pass = array(); //remember to declare $pass as an array
  6.     $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  7.     for ($i = 0; $i < 8; $i++) {
  8.         $n = rand(0, $alphaLength);
  9.         $pass[] = $alphabet[$n];
  10.     }
  11.     return implode($pass); //turn the array into a string
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement