Last post Jul 23, 2009 10:08 PM by howiem
Dec 07, 2007 03:16 PM|RTM1973|LINK
We are working with the AJAX control toolkit, and are in the process of implementing the password strength control in one of our applications. We have it up and running fine, but have encountered a bit of an obstacle. What we would like to do is check
via codebehind to see if the parameters we have set for passwords are valid. In other words, a method that would return a true/false for the password. However, I am not finding any way to accomplish this with the control. To use a real world example, here
is what we want to do:
I thought there would be a simple way to do this, but it either does not exist, or we are overlooking something... This is a really great control, but I am hoping we are not going to have to write a regular expression in our update method to determine if
we can proceed or not.
Has anyone else encountered this issue?
Dec 13, 2007 09:29 AM|Jonathan Shen – MSFT|LINK
User clicks 'update' button, and we check to see if the password is valid before updating the database (or, we do not enable the button until the password is strong)
Yes , we shall hide the Button and attach the keypress handler to the TextBox. The added handler will detect the PasswordStrength's password strength. In this sample , if the returned password strength is over 50 , then we show the Button.
_getPasswordStrength function will return a integer which is between 1 to 100. 1 is the weakest and 100 is the strongest.
Here is the working sample.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server">
padding:2px 2px 2px 2px;
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:TextBox ID="TextBox2" Width="150" TextMode="Password" runat="server" autocomplete="off" onkeypress="getPasswordStrengthState()" /><br />
<asp:Label ID="TextBox2_HelpLabel" runat="server"/><br />
<ajaxToolkit:PasswordStrength ID="PasswordStrength2" BehaviorID="myPSBID" runat="server" TargetControlID="TextBox2"
DisplayPosition="RightSide" StrengthIndicatorType="BarIndicator" PreferredPasswordLength="15"
BarBorderCssClass="BarBorder_TextBox2" MinimumNumericCharacters="1" MinimumSymbolCharacters="1"
TextStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent" RequiresUpperAndLowerCaseCharacters="true" />
<asp:Button ID="Button1" runat="server" Text="Button" style="display:none"/>
$get("<%=Button1.ClientID%>").style.display = '';
I have tested on IE7 & Firefox 2.0 . I'm using AJAX Control Toolkit V11119.
Jul 23, 2009 09:57 PM|howiem|LINK
An awesome workaround....
However it truly is mystifying why such a nice control lacks the obvious properties that you ought to be able to set in code.behind or on client properties
passwordstrength.required = strong
Thanks for the post though - cost me 40 minutes though scouring the net for it.
Pity the relevant sample on the asp.toolkit page doesn't have a community content or comments section. I would save many others a ton of time.
My 2 cents.
Jul 23, 2009 10:08 PM|howiem|LINK
Johnathon's code is great but if a user backspaces the command button remains visible.
I don't know enough about the <script> stuff to extend it to continue checkking and make the button dissapear if the user backspaces (thus reducing the current strength).