daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 143 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $username = $_POST['username'];
  2. $password = $_POST['password'];
  3. $confirm_password = $_POST['confirm_password'];
  4.  
  5. $password_filter1 = '/(?=.*[a-zA-Z0-9]{6})/m';  //Password contains more then 6 char
  6. $password_filter2 = '/(?=.*[A-Z])/m';           //Capital letter
  7. $password_filter3 = '/(?=.*d)/m';              //A digit
  8.  
  9. if (!empty($password & $confirm_password)) {
  10.  if ($password === $confirm_password) {
  11.   if (preg_match($password_filter1, $password)) {
  12.    if (preg_match($password_filter2, $password)) {
  13.     if (preg_match($password_filter3, $password)) {
  14.      //If everything is true do this
  15.     } else {
  16.      $password_error = "Your password must contain at least 1 number";
  17.     }
  18.    } else {
  19.     $password_error = "You're password must have at least 1 capital letter";
  20.    }
  21.   } else {
  22.    $password_error = "You're password must be at least 6 characters long";
  23.   }
  24.  } else {
  25.   $password_error = "The passwords do not match";
  26.  }
  27. } else {
  28.  $password_error = "You must enter a password";
  29. }
  30.      
  31. $password_filter1 = '/(?=.*[a-zA-Z0-9]{6})/m';  //Password contains more then 6 char
  32. $password_filter2 = '/(?=.*[A-Z])/m';           //Capital letter
  33. $password_filter3 = '/(?=.*d)/m';              //A digit
  34.      
  35. $has_at_least_6_chars = '/(?=.*[a-zA-Z0-9]{6})/';
  36. $has_a_capital_letter = '/(?=.*[A-Z])/';
  37. $has_a_digit = '/(?=.*d)/';
  38.      
  39. function has_a_capital_letter($str) {
  40.     return preg_match('/(?=.*[A-Z])/', $str);
  41. }
  42.  
  43. //...
  44.  
  45. if (!has_a_capital_letter($password)) {
  46.     $password_error = "Your password must have at least 1 capital letter";
  47. }
  48.      
  49. if (empty($password & $confirm_password)) {
  50.     $password_error = "You must enter a password";
  51. }
  52. elseif ($password !== $confirm_password) {
  53.     $password_error = "The passwords do not match";
  54. }
  55. elseif (!preg_match($has_at_least_6_chars, $password)) {
  56.     $password_error = "Your password must be at least 6 characters long";
  57. }
  58. elseif (!preg_match($has_a_capital_letter, $password)) {
  59.     $password_error = "Your password must have at least 1 capital letter";
  60. }
  61. elseif (!preg_match($has_a_digit, $password)) {
  62.     $password_error = "Your password must contain at least 1 number";
  63. }
  64. else {
  65.     //If everything is true do this
  66. }
  67.      
  68. $password = "Hell0!";
  69. $confirm_password = "Hell0!";
  70.      
  71. elseif (strlen($password) < 6) {
  72.     $password_error = "Your password must be at least 6 characters long";
  73. }
  74.      
  75. function getPasswordError($password, $confirm_password)
  76. {
  77.     $password_filter1 = '/(?=.*[A-Z])/m';
  78.     $password_filter2 = '/(?=.*d)/m';  
  79.  
  80.     if (empty($password) || empty($confirm_password)) {
  81.         return 'You must enter a password';
  82.     }
  83.  
  84.     if (strlen($password) < 6) {
  85.         return 'Your password must be at least 6 characters long';
  86.     }
  87.  
  88.     if ($password !== $confirm_password) {
  89.         return 'The passwords do not match';
  90.     }
  91.  
  92.     if (!preg_match($password_filter1, $password)) {
  93.         return 'Your password must have at least 1 capital letter';
  94.     }
  95.  
  96.     if (!preg_match($password_filter2, $password)) {
  97.         return 'Your password must contain at least 1 number';
  98.     }
  99.  
  100.     return false;
  101. }
  102.      
  103. $password_error = getPasswordError($password, $confirm_password);
  104.  
  105. if ($password_error !== false) {
  106.     echo $password_error; // or do whatever with the data
  107. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top