Solved

Authenticate password with regular expressions.

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…

778 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