We help IT Professionals succeed at work.

Password strength generator

countrymeister
countrymeister used Ask the Experts™
on
I want to generate a password strength generator, indicating to the users the strength of their password.
The password needs to be atleast six characters, need to have one upper case letter, one number and one special character.
I need to do this in .net, can someone help me with this.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
You could use regular expressions for this purpose.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_27241719._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
        //The password needs to be atleast six characters, need to have one upper case letter, one number and one special character.
        function checkPassword(box, banner)
        {
            var messages = ['Weak', 'Weak', 'Good', 'Strong'];
            var matchCount = 0;
            var text = box.value;
            var label = document.getElementById(banner);

            if (text.match(/^.{6,}/)) {
                matchCount++;
            }
            
            if (text.match(/[A-Z]/)) {
                matchCount++;
            }
            
            if (text.match(/\d/)) {
                matchCount++;
            }
            
            if (text.match(/[.!@#$%^&*]/)) {
                matchCount++;
            }
            
            label.innerHTML = messages[matchCount];
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onKeyUp="checkPassword(this, 'Label1');" /><asp:Label ID="Label1" runat="server" Text="Label" />
    </div>
    </form>
</body>
</html>

Open in new window

Author

Commented:
Here  is what I did to create my password strength generator

<asp:TextBox id="ItxtPassword"   runat="server" />
            <ajaxToolkit:PasswordStrength runat="server" ID="PS"
                    TargetControlID="ItxtPassword"
                    DisplayPosition="RightSide"
                    MinimumSymbolCharacters="1"
                    MinimumUpperCaseCharacters="1"
                    MinimumNumericCharacters="1"
                    PreferredPasswordLength="8"
                    CalculationWeightings="25;25;15;35"
                    RequiresUpperAndLowerCaseCharacters="true"
                    TextStrengthDescriptions="Poor; Weak; Good; Strong; Excellent"
                    StrengthIndicatorType="BarIndicator"
                    HelpHandlePosition="AboveLeft"
                    BarBorderCssClass="barIndicatorBorder"
                    StrengthStyles="barIndicator_poor; barIndicator_weak; barIndicator_good; barIndicator_strong; barIndicator_excellent">
               </ajaxToolkit:PasswordStrength>

Author

Commented:
I solved this using an ajax pasword strength extender
This was a soluiton wher the author made a genuine effort to help.
The rest sent me some links for jquery