Skip to content

Instantly share code, notes, and snippets.

@earth3300
Created November 23, 2018 17:40
Show Gist options
  • Select an option

  • Save earth3300/8eda6f140fceebe21695bc773be0a85b to your computer and use it in GitHub Desktop.

Select an option

Save earth3300/8eda6f140fceebe21695bc773be0a85b to your computer and use it in GitHub Desktop.
Password validation using regex.
/**
* Password Validation
*
* @link https://stackoverflow.com/a/21456918/5449906
*
* @param $string
*
* @return bool
*/
private function validatePassword( $password )
{
if ( false ) {
/** Minimum eight characters, at least one letter and one number: */
$regex = "/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}/";
/** Minimum eight characters, at least one letter, one number and one special character: */
$regex = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/";
/** Minimum eight characters, at least one uppercase letter, one lowercase letter and one number: */
$regex = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/";
/** Minimum eight and maximum 10 characters, at least one uppercase letter, one lowercase letter, one number and one special character: */
$regex = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,10}$/";
}
else
{
return false;
}
}
@earth3300
Copy link
Author

Non-functional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment