Solved

Authenticate password with regular expressions.

Posted on 2014-01-17
3
210 Views
Last Modified: 2014-01-28
I am looking for a way to authenticate a password in C# with regular expressions rather than one big nested set of conditions.

The requirements are,

password has to be at least 6 characters long,
password has to contain a combination of upper / lower case letters (or) password has to contain a punctuation symbol from a given set.

Any ideas/
0
Comment
Question by:Blowfelt82
3 Comments
 
LVL 8

Expert Comment

by:Surrano
ID: 39788170
1. Length is easier to check with length than with regex but the simplest regex to match this is (......) (note that there are no ^ nor $ so it can be of any length)

2. Upper-lowercase or puctuation should be piece of cake, e.g.: ([A-Z].*[a-z]|[a-z].*[A-Z]|[-.,;/?])
The only pitfall to watch out for is that a dash must come as first or last of a bracketed set (preferably first)

3. If you wish to combine the two into a single regex, though, it gets much more complicated than it'd worth doing.
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39788506
(?=.{6})((?=.*[A-Z])(?=.*[a-z])|.*[a given set])
0
 
LVL 9

Expert Comment

by:Derek Jensen
ID: 39789909
Why not just make them all required? This can only make for a more secure password, regardless of how much I hate required symbols in passwords. ;-)

(?=.{6,12})((?=.*[A-Z])(?=.*[a-z])(?=.*[sym. char set]))

Open in new window

I also added a max length to the passwd, in case there's some kind of datatype restriction or something, but passwords should be stored encrypted anyway, so this shouldn't be an issue. :-)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now