Solved

Authenticate password with regular expressions.

Posted on 2014-01-17
3
215 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

856 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