tjone270

4-Part Password Generator

Aug 8th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2.   $alphabetUpper = 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");
  3.   $alphabetLower = array();
  4.   foreach ($alphabetUpper as $letter) {
  5.     array_push($alphabetLower, strtolower($letter));
  6.   }
  7.   $numbers = range(0, 9);
  8.   $specialChars = array("!", "@", "#", "$", "%", "^", "&", "*", "_", "|", "/", "\\", ".");
  9.  
  10.   $characterSet = array_merge($alphabetUpper, $alphabetLower, $numbers, $specialChars);
  11.  
  12.   function generateRandomPassword() {
  13.     global $characterSet;
  14.     $count = (count($characterSet) - 1);
  15.     $segment1 = ($characterSet[rand(0, $count)] . $characterSet[rand(0, $count)] . $characterSet[rand(0, $count)]);
  16.     $segment2 = ($characterSet[rand(0, $count)] . $characterSet[rand(0, $count)] . $characterSet[rand(0, $count)]);
  17.     $segment3 = ($characterSet[rand(0, $count)] . $characterSet[rand(0, $count)] . $characterSet[rand(0, $count)]);
  18.     $segment4 = ($characterSet[rand(0, $count)] . $characterSet[rand(0, $count)] . $characterSet[rand(0, $count)]);
  19.     return ($segment1 . "-" . $segment2 . "-" . $segment3 . "-" . $segment4);
  20.   }
  21. ?>
  22.  
  23. <!DOCTYPE html>
  24. <html lang="en">
  25.   <head>
  26.     <!-- Created by Thomas Jones of TomTec Solutions (07/08/16) -->
  27.     <title>4-Part Password Generator</title>
  28.     <meta charset="utf-8">
  29.     <meta name="viewport" content="width=device-width, initial-scale=1">
  30.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  31.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  32.     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  33.   </head>
  34.   <body>
  35.     <div class="container">
  36.       <div class="jumbotron" style="text-align: center;">
  37.         <h1><strong>4-Part Password Generator</strong></h1>
  38.         <p>Your generated 4-Part Password:</p>
  39.         <pre><?php echo generateRandomPassword(); ?></pre>
  40.         <a href="passgen.php">Re-Generate</a>
  41.       </div>
  42.     </div>
  43.   </body>
  44. </html>
Add Comment
Please, Sign In to add comment