Home >Web Front-end >JS Tutorial >How Can I Create a Secure Password Regex with Minimum Length, Upper/Lowercase, Numbers, Special Characters, and Excluded Strings?

How Can I Create a Secure Password Regex with Minimum Length, Upper/Lowercase, Numbers, Special Characters, and Excluded Strings?

DDD
DDDOriginal
2024-12-16 04:23:13276browse

How Can I Create a Secure Password Regex with Minimum Length, Upper/Lowercase, Numbers, Special Characters, and Excluded Strings?

Regular Expression for Password with Enhanced Security

To ensure robust password security, a comprehensive regular expression is essential. It should adhere to the following criteria:

  • Minimum Eight Characters: The password must contain at least eight characters.
  • Uppercase and Lowercase Letters: It should include both uppercase and lowercase letters.
  • Number and Special Character: Additionally, it must have at least one number and one special character from $#?!.
  • Exclusion: Certain strings, such as "old password", "password", and "websitename", should not be included.

Here's an improved regular expression that meets these requirements:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$#?!])[^old password|password|websitename]{8,}$

This expression ensures that the password:

  • Has a minimum length of eight characters.
  • Contains at least one uppercase letter, one lowercase letter, one number, and one special character.
  • Excludes specific prohibited strings.

By implementing this regular expression, you can enhance the security of your password validation process and protect against common password weaknesses.

The above is the detailed content of How Can I Create a Secure Password Regex with Minimum Length, Upper/Lowercase, Numbers, Special Characters, and Excluded Strings?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn