Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
how to autthenticate valide password in C#.net


that accepts minimum length is 8 char and it contains combination of upper&lower case characters,

numerals and must have at least one special character
Posted
Comments
syed shanu 20-Mar-14 1:50am    
chk this http://stackoverflow.com/questions/9477906/password-must-be-8-characters-including-1-uppercase-letter-1-special-character use google u hav eeverything in that

1 solution

Many try to use Regular Expressions, but this is not the best way to evaluate password. Some things are surprisingly difficult or impossible to match using the Regex. At the same time, your criteria look very simple.

The algorithm you really need would be very simple, too. First, then length is known immediately: string.Length. Now, here is what you need to do. Create some local integer variables per the class of character. Say, one for upper-case letter, another for lower-case latter, one more for, say, punctuations, digits, etc. Initialize all of them to zero. Then loop through all the characters of the selected password string. For each character, check up if it belongs to one of the character class and increment corresponding variable.

In the loop, use System.Char methods to classify the current character:
http://msdn.microsoft.com/en-us/library/7f0ddtxh(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/yyxz6h5w(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/6w3ahtyy(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/d1x97616(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/9s91f3by(v=vs.110).aspx[^], and so on…

On the exit from the loop, you will have complete number of characters in each class.

That's all. Simple, isn't it?

—SA
 
Share this answer
 
Comments
VICK 20-Mar-14 2:30am    
Great. My 5+.
Sergey Alexandrovich Kryukov 20-Mar-14 10:48am    
Thank you very much.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900