Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 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 April 12th, 2010, 08:47 PM
Registered User
 
Join Date: Apr 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Check if the password contains non-alphanumeric character

Hi,

My ChangePassword method returns a boolean value indicating whether the change of password has been successful or not. When the user enters a new password, I want to check if the password length is at least 8 and there is at least one non-alphanumeric character(both these parameters specified in the web.config file). If I want to check in my code if the password entered is at least 8 characters, I would write some code like this:

if(newpassword.Length < 8)

{

//do something

}

Like the Length property, is there some property that can check if the password contains at least one non-alphanumeric character???

Thank you!
 
Old April 12th, 2010, 09:03 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

If you are comfortable with Regular Expressions, you can try using Regex to validate the password.

It is part of
using
System.Text.RegularExpressions; namespace

I will try to get some small code snippet for you

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
 
Old April 12th, 2010, 09:37 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Here is a hint

privatebool CheckPasswordForNonAlpha(String sPassword)
{
string sPattern;
sPattern =
"[^a-zA-Z0-9\n\r\t ]";
Regex oReg = newRegex(sPattern, RegexOptions.IgnoreCase);
return oReg.IsMatch(sPassword);

}

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
password check with RegEx neutcomp BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 5 January 7th, 2009 05:26 PM
How to check programmatically check the password? thomaskelly ASP.NET 1.0 and 1.1 Basics 1 May 16th, 2008 08:49 PM
Password Requires more than one character dbird VB.NET 0 February 17th, 2007 01:53 PM
Check Windows-Password Bernd VS.NET 2002/2003 1 October 6th, 2005 12:32 PM
Can't check data from a form. (Like password) scifo Beginning PHP 3 August 7th, 2003 01:31 PM





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