Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

I need help with a .NET Regex password expression

Posted on 2011-10-11
5
Medium Priority
?
238 Views
Last Modified: 2012-05-12
The requirements for the expression are:
- No more than two characters can repeat
- Minimum size of 8 characters
- Must contain a least one upper case character
- Must contain a least one special character
- Must contain at least one numeric digit

I have already tried Reglib but am not familiar enough with them to create this expression. Any suggestions?

Thank you for your help
0
Comment
Question by:Elliott Ward
  • 3
5 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36951619
By "No more than two characters can repeat" I interpret this as allowing:
abababab1&
but not
aaababa1&

Try this (I'm just about to test it now though!):
^(?=.*[-`~!@#$%\^&*()_+=\[\]{}\\|;':",./<>?])(?=.*\d)(?=.*[A-Z])(?!.*?(.)\1\1)).{8,}
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36951671
After testing, I needed to make a minor change. This appears to work:
^(?=.*[-`~!@\#$%\^&*()_+=\[\]{}\\|;':",./<>?])(?=.*\d)(?=.*[A-Z])(?:(?!(.)\1\1).){8,}$
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 1400 total points
ID: 36951689
In VB.NET, hopefully this will work:
Dim re As Regex = New Regex("^(?=.*[-`~!@\#$%\^&*()_+=\[\]{}\\|;':"",./<>?])(?=.*\d)(?=.*[A-Z])(?:(?!(.)\1\1).){8,}$")

(Code generated by myregextester.com)
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 600 total points
ID: 36951965
If by "no more than two characters can repeat" you mean any single character can appear no more than one time in the password then change this part of Terry's pattern:

(.)\1\1

Open in new window


to

(.).*?\1.*?\1

Open in new window

0
 

Author Closing Comment

by:Elliott Ward
ID: 36955216
Thank you both for your assistance. This is exactly what I needed.
0

Featured Post

Industry Leaders: 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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
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…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

564 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