Password Strength Using Regular Expression IN PHP

<?php
function password(){
$password = ‘user-pass’;

//Password must be at least 8 characters in length.
//Password must at least one upper case letter.
//Password must at least one number.
//Password must at least one special character.

$uppercase = preg_match(‘@[A-Z]@’, $password);
$lowercase = preg_match(‘@[a-z]@’, $password);
$number = preg_match(‘@[0-9]@’, $password);
$specialChars = preg_match(‘@[^w]@’, $password);

if(!$uppercase || !$lowercase || !$number || !$specialChars || strlen($password) < 8) {
return ‘false | Weak Password’;
}else{
return ‘true | Strong Password’;
}
}
echo password();

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.