When the user registers and modifies, resets the password, enforces the password to achieve certain complexity, is one of the effective measures to reduce the theft number.
in the code to check the complexity of the password need to use a regular expression, such as requiring the password must contain numbers, lowercase or uppercase, special characters, the number of characters between 8-30, the corresponding regular expression is as follows:
var regex = new Regex (@ "=.*[0-9]) #必须包含数字 (? =.*[a-za-z]) #必须包含小写或大写字母 (? = ([\x21-\x7e]+) [^a-za-z0-9]) # Special symbols must be included. {8,30} #至少8个字符, up to 30 characters ", Regexoptions.multiline | Regexoptions.ignorepatternwhitespace);
If the requirement must contain lowercase, uppercase letters, the above (? =.*[a-za-z]) should be changed to:
(? =.*[a-z]) (? =.*[a-z])
Related Bo Q: How to write a regular expression that matches all special characters on the keyboard
[Go] C # regular expression to check password complexity