Advertisement
topherbones

Password Validation

Aug 10th, 2022
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. // PHP PASSWORD VALIDATE
  2. // Given password
  3. $password = 'user-input-pass';
  4.  
  5. // Validate password strength
  6. $uppercase = preg_match('@[A-Z]@', $password);
  7. $lowercase = preg_match('@[a-z]@', $password);
  8. $number    = preg_match('@[0-9]@', $password);
  9. $specialChars = preg_match('@[^\w]@', $password);
  10.  
  11. if(!$uppercase || !$lowercase || !$number || !$specialChars || strlen($password) < 8) {
  12.     echo 'Password should be at least 8 characters in length and should include at least one upper case letter, one number, and one special character.';
  13. }else{
  14.     echo 'Strong password.';
  15. }
  16.  
  17. # SOURCE https://www.codexworld.com/how-to/validate-password-strength-in-php/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement