SHARE
TWEET

Untitled

a guest Dec 2nd, 2019 158 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <form id='login' action='log_in.php' method='post' accept-charset='UTF-8'>
  3. <fieldset >
  4. <legend>Login</legend>
  5. <input type='hidden' name='submitted' id='submitted' value='1'/>
  6.  
  7. <label for='username' >Username:
  8. </label>
  9.  
  10.  
  11. <input type='text' name='username' id='username'/>
  12.  
  13. <label for='password' >Password:
  14. </label>
  15.  
  16. <input type='password' name='password' id='password'/>
  17.  
  18.  
  19. <label for='confirm_password' > Confirm Password:
  20. </label>
  21.  
  22. <input type='password' name='confirm_password' id='confirm_password'/>
  23.  
  24.  
  25.  
  26. <input type='submit' name='Submit' value='Submit' />
  27.  
  28. </fieldset>
  29. </form>
  30.  
  31. <?php
  32.  
  33.  
  34.  
  35. if (isset($_POST["Submit"])){
  36.     $errors = array();
  37.     $user = $_POST['username'];
  38.     $password = $_POST['password'];
  39.     $hash = password_hash($password, PASSWORD_DEFAULT);
  40.     $log_name = "validation.log";
  41.     $log_timestamp = date("Y-m-d", time());
  42.     $log_data = $user . " " . $hash . " " . $log_timestamp;
  43.  
  44. //checks the username for the REGEX requirements
  45.     if(preg_match("/^[0-9a-zA-Z_]{6,12}$/", $_POST["username"]) === 0)
  46.     $errors[] ="Invalid username. A username must contain 6-12 characters and can only use numbers, letters, and underscores.";
  47. //checks the password for the REGEX requirements
  48.     if(preg_match("/^.*(?=.{8,16})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["password"]) === 0)
  49.     $errors[] ="Invalid password. Password must be 8-16 characters and contain at least one uppercase letter, one number, one special character and no spaces.";
  50. //Makes sure the passwords match
  51.     if ($_POST["password"] !==  $_POST["confirm_password"])
  52.     $errors[] ="Passwords do not match.";
  53. //checks if username is blank
  54.     if (empty($_POST['username']))
  55.     $errors[] ="Username cannot be left blank.";
  56. //checks if password is blank
  57.     if(empty($_POST["password"]))
  58.     $errors[] ="Password cannot be left blank.";
  59. //checks to see that the user entered their password twice
  60.     if(empty($_POST["confirm_password"]))
  61.     $errors[] ="Please enter your password in the Confirm Password field. It cannot be left blank.";
  62. //prints out any errors
  63.     if (count($errors) > 0){
  64.         foreach ($errors as $error)
  65.             echo $error."<br/>";
  66.         }
  67. // if successful, writes data into a log file and prints the password hash
  68.     else{
  69.         echo $hash;
  70.         file_put_contents($log_name, $log_data);
  71.    
  72.     }
  73. }
  74.  
  75. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top