Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 1st, 2006, 01:46 PM
Registered User
 
Join Date: Mar 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regualr Expression Password Matching

Is there a way in one single Reg Expression to validate a password string that satisfies,

1. Must have at least one upper case letter [A-Z]
2. Must have at least one lower case letter [a-z]
3. Must have at least one number [0-9]
4. Must have at least one special character from [! $ % ^ & * ( ) _ + = < > ? / \ | ] [ { }]
5. The string length should be between 6 and 25.

Note: The above said steps 1-4 characters can appear in any random order.

I have a solution, but the problem with this one is, I have to check for each named group,
"^((?<lower>[a-z])|(?<upper>[A-Z])|(?<number>[0-9])|(?<symbol>[\\$\\!\\%\\^\\#]))+$"

In C# code I would check as,

if (aMatch.Success && aMatch.Groups["lower"].Success
&& aMatch.Groups["upper"].Success && aMatch.Groups["number"].Success
&& aMatch.Groups["symbol"].Success)
{
Valid Password;
}
else
Not valid;

Is there a better solution, such as writing the whole thing in one Reg Expression?

Thanks,
Chandra

 
Old March 24th, 2006, 08:32 PM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The Regular Expression engine is fairly fast, so defining your RegEx string that satisfies your requirements is the way I would go. Here's an example RegEx string which would satisfy most of your conditions using RegEx.IsMatch(inputstring, regexstring):

My regexstring sample:

([a-z]+[A-Z]+\w+?[_]+[0-9]+)|([A-Z]+[a-z]+\w+?[_]+[0-9]+)|([0-9]+[_]+[A-Z]+[a-z]+)|([_]+[A-Z]+[a-z]+[0-9]+)|([_]+[0-9]+[A-Z]+[a-z]+)

Note that I only used the underscore special character, but you can simply insert any number of special characters you want (escpaing out the characters where necessary).

I've tested the string out with RegEx Buddy for the following input strings:

portsMouth_5875
Portmouth_5875
5857_Portmsouth
_Portsmouth5875
_5875Portsmouth

All of them matched up successfully.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression matching sub string mayasht Pro Java 3 August 8th, 2007 05:32 AM
Regular expression to select non-matching pattern Neuron BOOK: Beginning Regular Expressions 1 June 12th, 2006 10:06 AM
Regualr Expression Password Matching Chandra Paladugu C# 1 March 2nd, 2006 04:47 PM
Regular Expression for password kitkits ASP.NET 1.0 and 1.1 Basics 2 April 28th, 2005 11:44 PM
Regular Expression for password Baby_programmer ASP.NET 1.0 and 1.1 Basics 1 December 28th, 2004 01:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.