如何限制密码包含两个大写字母,两个小写字母,一个特殊数字和两个特殊字符。 [英] how to restrict a password contain two uppercase letter,two lower case,one special digit,and two special charcter.
本文介绍了如何限制密码包含两个大写字母,两个小写字母,一个特殊数字和两个特殊字符。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何限制密码包含两个大写字母,两个小写字母,一个特殊数字和两个特殊字符。
解决方案
甚至不尝试做它在SQL中。
你可以,但这是一个糟糕的主意,因为SQL永远不会看到基于文本的密码 - 它应该只看到盐渍的密码哈希:密码存储:如何操作。 [ ^ ]
在任何.NET语言中执行它都是相同的过程:计算每种类型的数量,并检查是否有正确的数字。
参见 char.IsUpper [ ^ ], char.IsLower [ ^ ]和 char.IsDigit [ ^ ] - 如果它不是其中之一,则它是一个特殊字符!
您可以使用正则表达式检查密码。
在您的代码中,您可以使用Regex.IsMatch()函数检查密码。您插入输入的值和模式。该模式包含有关您的密码必须强大的信息。
检查此链接 [ ^ ] for一些模式的例子。
模式@(?= ^。{6,255}
< BLOCKQUOTE>)((= * \d?)(= * [AZ]。)(= * [AZ]?)|?(?= * \d)(= * [^ A- ZA-Z0-9])(= * [AZ])|?(= * [^ A-ZA-Z0-9])(= * [AZ])(= * [AZ]???。 )|(?=。* \ d)(?=。* [AZ])(?=。* [^ A-Za-z0-9]))^。*接近你想要什么。
how to restrict a password contain two uppercase letter,two lower case,one special digit,and two special charcter.
解决方案
Don't even try to do it in SQL.
You can, but it's a poor idea, because SQL should never see a text based password - it should only ever see salted hashes of passwords: Password Storage: How to do it.[^]
And doing it in any .NET language is the same process: Count the number of each type, and check there are the right number.
See char.IsUpper[^], char.IsLower[^] and char.IsDigit[^] - if it isn't one of them, it's a special character!
You can check the password using Regular Expressions.
In your code you can check the password with the Regex.IsMatch() function. You insert the entered value and a pattern. The pattern holds information about how 'strong' your password must be.
Check this link[^] for a couple of examples of patterns.
The pattern@"(?=^.{6,255}
)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*" comes close to what you want.
这篇关于如何限制密码包含两个大写字母,两个小写字母,一个特殊数字和两个特殊字符。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文