Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2. class PasswordManager{
  3.     public $username = '';
  4.     public $password = '';
  5.     protected $encryptedPassword = '';
  6.  
  7.     function Form(){                                   
  8.         $output = "<h2>Password Manager</h2><form id='password-form' action='' method='POST' >
  9.                         <p><label>Username<span class='required'>*</span> </label><input class='text-field' type='text' name='txtusername' /></p>
  10.                         <p><label>Password<span class='required'>*</span> </label><input class='text-field' type='text' name='txtpassword' /></p>
  11.                         <p><input type='submit' value='New user' class='submit-button' /></p>
  12.                         <p><input type='submit' value='Validate Password' class='vp-button' /></p>                       
  13.                     </form>
  14.                     </body>
  15.                     </html>";
  16.        
  17.         return $output;
  18.     }
  19.  
  20.     protected function encrypt($password, $encryptedPassword) {
  21.         $encryptedPassword = hash('md5', $password);
  22.         return $encryptedPassword;
  23.     }
  24.  
  25.     protected function verifyPassword($username, $password) {
  26.     }
  27.  
  28.     function validatePassword($password) {
  29.         $error = "";
  30.         if (!preg_match('/\s/', $password)) {
  31.             $error .= "<p class='error message'>The password must not contain any whitespace.</p>";
  32.             echo $error;
  33.         } elseif (strlen($password) <6) {
  34.             $error .= "<p class='error message'>The password must be at least 6 characters long.</p>";
  35.             echo $error;
  36.         } elseif (!preg_match('/[0-9][\W]/', $password)) {
  37.             $error .= "<p class='error message'>The password must have at least one digit and symbol.</p>";
  38.             echo $error;
  39.         } elseif (!preg_match('/[A-Z][a-z]/', $password)) {
  40.             $error .= "<p class='error message'>The password must contain at least one uppercase and at least one lowercase letter.</p>";
  41.             echo $error;
  42.         }
  43.         return true;
  44.     }
  45.  
  46.     function setNewPassword($post_array) {
  47.         $myfile = fopen("password.txt", "w");
  48.         fwrite($myfile, $post_array["txtusername"]);
  49.         fwrite($myfile, md5(post_array["txtpassword"]));
  50.         fclose($myfile);
  51.     }
  52.  
  53.  
  54. }
  55.  
  56.  
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement