Since you don't care about it following a particular pattern, just
want to make sure it has a variety of characters it's easier to just
use a loop than to use Regex. Also for "strong" password you usually
want to test for a non-alphanumeric character as well.
HTH,
Sam
using System;
namespace CommandTest
{
public class StrongPassword
{
public static bool IsStrongPassword(string password)
{
if (password == null || password.Length < 8)
{
return false;
}
// custom rule, first char must be a letter
if (!Char.IsLetter(password[0]))
{
return false;
}
bool hasLetter = false;
bool hasDigit = false;
bool hasOther = false;
foreach(char c in password)
{
if (Char.IsLetter(c))
{
hasLetter = true;
}
else if (Char.IsDigit(c))
{
hasDigit = true;
}
else
{
hasOther = true;
}
}
return hasLetter && hasDigit && hasOther;
}
public static void Test()
{
Test("hey");
Test("password");
Test("pa$$word");
Test("pa$$w0rd");
}
public static void Test(string password)
{
Console.WriteLine("{0,-12}: {1}", password,
IsStrongPassword(password));
}
}
}
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Mon, 21 Aug 2006 13:33:41 -0400, "UJ" <fr**@nowhere.comwrote:
>Does anybody have lying around a Regex for a strong password (or a routine
to check it). I'd like the normal First character has to be a character,
total of 8 characters and has to have at least one number in it.
TIA - Jeff.