Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Authenticate password with regular expressions.

Posted on 2014-01-17
3
Medium Priority
?
227 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 85

Accepted Solution

by:
ozo earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

783 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