C# Password Validation

The following function uses a Regular Expression, which you can tweak to just about anything, to check if a password is 8 to 15 in length and contains atleast one digit or symbol.

using System.Text.RegularExpressions;

public bool ValidatePassword(string tPass) { Regex passreg = new Regex("^(?=.*[d$!%^&*()]).{8,15}$”);

Match mRes = passreg.Match(tPass); return mRes.Success; }

Returns true if it matches, false if it doesn’t!

  • Share/Bookmark

2 Comments

IVAN RIOSSeptember 15th, 2004 at 11:22 pm

Quisiera saber como hago para comparar el password que digita el usuario con el que tengo en mi base de datos.

La base de datos que estoy utilizando es MySql y el lenguaje de programacion es C#.

sankaAugust 18th, 2009 at 9:38 pm

thanks !! … it really helped

Leave a comment

Your comment