Click here to Skip to main content
15,888,251 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
how to restrict a password contain two uppercase letter,two lower case,one special digit,and two special charcter.
Posted

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!
 
Share this answer
 
Comments
rajshreelande 27-Oct-14 5:10am    
can u please tell me how to do it in a sqlserver2008,
and the criteria for the password changes different client type as,
one wants:1 uppercase,2 lowercase,2 digit,1 special char
another wants:two uppercase letter,two lower case,one special digit,and two special charcter.
how to do it in sqlserver 2008
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.
 
Share this answer
 
Comments
Maciej Los 27-Oct-14 5:01am    
+5!
rajshreelande 27-Oct-14 5:10am    
can u please tell me how to do it in a sqlserver2008,
and the criteria for the password changes different client type as,
one wants:1 uppercase,2 lowercase,2 digit,1 special char
another wants:two uppercase letter,two lower case,one special digit,and two special charcter.
how to do it in sqlserver 2008
sashkhdr 27-Oct-14 5:14am    
by using regular expression we can do that one..
http://www.regexr.com/
you can get wat u want
Eduard Keilholz 27-Oct-14 5:15am    
I encourage you to NOT do it in the database. The password should never reach the database in it's original form, you should have encrypted or hashed the password before it reaches your data layer. Although it's possible I recommend you to handle this in code and make the several different password strength demands using a setting. Handling all this in the database your be bad design.
CSS
by using regular expression we can do that one..
http://www.regexr.com/
you can get wat u want


As Per Your Requirement You Can Use This One
Delphi
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
 
Share this answer
 
v2
Comments
Eduard Keilholz 27-Oct-14 5:17am    
Please don't comment to and then copy my answer and make it very incomplete.

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