re8nifle

CCReddit PHP

Oct 5th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. <?php
  2.   function randomPassword() {
  3.     $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
  4.     $pass = array(); //remember to declare $pass as an array
  5.     $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  6.     for ($i = 0; $i < 12; $i++) {
  7.         $n = rand(0, $alphaLength);
  8.         $pass[] = $alphabet[$n];
  9.     }
  10.     return implode($pass); //turn the array into a string
  11.   }
  12.  
  13.   $pass = randomPassword();
  14.   $file = fopen("pass.txt", "w") or die("Unable to open file!");
  15.   fwrite($file, $pass);
  16.   fclose($file);
  17.   echo $pass;
  18. ?>
Add Comment
Please, Sign In to add comment