Click here to Skip to main content
13,447,595 members (52,681 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads


184 bookmarked
Posted 11 Jan 2011

ASP.NET - Password Strength Indicator using jQuery and XML

, 31 Jul 2012
ASP.NET Password Strength Indicator somewhat similar to AJAX PasswordStrength extender control behavior and implemented by using jQuery and XML.
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        btnSubmit.Click += new EventHandler(btnSubmit_Click);

    void btnSubmit_Click(object sender, EventArgs e)
        PasswordSetting passwordSetting = Helper.GetPasswordSetting();
        StringBuilder sbPasswordRegx = new StringBuilder(string.Empty);

        //min and max
        sbPasswordRegx.Append(@"(?=^.{" + passwordSetting.MinLength + "," + passwordSetting.MaxLength + "}$)");

        //numbers length
        sbPasswordRegx.Append(@"(?=(?:.*?\d){" + passwordSetting.NumsLength + "})");

        //a-z characters

        //A-Z length
        sbPasswordRegx.Append(@"(?=(?:.*?[A-Z]){" + passwordSetting.UpperLength + "})");

        //special characters length
        sbPasswordRegx.Append(@"(?=(?:.*?[" + passwordSetting.SpecialChars + "]){" + passwordSetting.SpecialLength + "})");

        //(?!.*\s) - no spaces
        //[0-9a-zA-Z!@#$%*()_+^&] -- valid characters
        sbPasswordRegx.Append(@"(?!.*\s)[0-9a-zA-Z" + passwordSetting.SpecialChars + "]*$");

        if (Regex.IsMatch(txtPassword.Text, sbPasswordRegx.ToString()))
            ResultLabel.Text = "Password confront password policy!";
            ResultLabel.Text = "Password does not confront password policy!";

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Bryian Tan
Software Developer (Senior)
United States United States
I have over 10 years of experience working with Microsoft technologies. I have earned my Microsoft Certified Technology Specialist (MCTS) certification. I'm a highly motivated self-starter with an aptitude for learning new skills quickly.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180318.3 | Last Updated 31 Jul 2012
Article Copyright 2011 by Bryian Tan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid