"
ASP.NET (snapshot 2017) Microsoft documentation and samples

Testing the Strength of a Password (C#)

by Christian Wenz

Download Code or Download PDF

Passwords are required almost anywhere, so that lazy users tend to choose simple passwords which are easy to break. The PasswordStrength control in the ASP.NET AJAX Control Toolkit can check how good a password is.

Overview

Passwords are required almost anywhere, so that lazy users tend to choose simple passwords which are easy to break. The PasswordStrength control in the ASP.NET AJAX Control Toolkit can check how good a password is.

Steps

The PasswordStrength control extends a text box and checks whether the password in it is good enough. It offers a wealth of options via attributes; here are just some of them:

The StrengthIndicatorType provides the information how to present the strength of the password, as text (value "Text") or as a kind of progress bar (value "BarIndicator"). In the DisplayPosition attribute, you configure where the information appears. Here is a complete example, including the ASP.NET AJAX ScriptManager control, the PasswordStrength control and of course a text box where the user may enter a password. For the sake of demonstration, the latter form field is a regular text field and not a password field so that you can see during development what you are typing.

[!code-aspxMain]

   1:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   2:  <html xmlns="http://www.w3.org/1999/xhtml">
   3:  <head runat="server">
   4:   <title>Control Toolkit</title>
   5:  </head>
   6:  <body>
   7:   <form id="form1" runat="server">
   8:   <asp:ScriptManager ID="asm" runat="server" />
   9:   <div>
  10:   <asp:TextBox ID="Password" runat="server" />
  11:   <ajaxToolkit:PasswordStrength ID="ps1" runat="server" 
  12:   TargetControlID="Password" RequiresUpperAndLowerCaseCharacters="true" 
  13:   MinimumNumericCharacters="1" MinimumSymbolCharacters="1" 
  14:   PreferredPasswordLength="8" DisplayPosition="RightSide" 
  15:   StrengthIndicatorType="Text" />
  16:   </div>
  17:   </form>
  18:  </body>
  19:  </html>

Run the page and type away: Only after you have entered lowercase letters, uppercase letters, digits and symbols, the password is deemed as unbreakable .

Now the password is (quite) good

Now the password is (quite) good (Click to view full-size image)

Next



Comments ( )
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnet/web-forms/overview/ajax-control-toolkit/passwordstrength/testing-the-strength-of-a-password-cs.htm
< THANKS ME>