How do I verify in C# that the password contains at least X uppercase letters and at least Y numbers, and the entire string is longer than Z?
Thanks.
How do I verify in C# that the password contains at least X uppercase letters and at least Y numbers, and the entire string is longer than Z?
Thanks.
This should do it:
Password Strength:
First, I would read up on password strength, and double-check your policy to make sure you were doing the right thing (I couldn't tell you off hand):
Then I'd check other questions:
Then I'd get down to business.
Implementation:
You could use Linq:
You could use also regular expressions (which might be a good option to allow you to plug in more complicated validations in the future):
Or you could mix and match them.
If you had to do this multiple times, you could reuse the
Regex
instances by building a class:To count uppercase letters and digits:
and check
s.Length
for the lengthgood luck!
Short and clear using LINQ Where() method: