Solved

Authenticate password with regular expressions.

Posted on 2014-01-17
3
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…

628 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