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:
<div mce_keep="true">User comes to a 'change password' page and enters their new password.</div>
<div mce_keep="true">Control shows the user if their password is strong or not (no problems so far)</div>
<div mce_keep="true">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)</div>
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.
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.
I have tested on IE7 & Firefox 2.0 . I'm using AJAX Control Toolkit V11119.
Best regards,
Jonathan
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
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
and
passwordstrength.CurrentStrength
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.
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).
RTM1973
0 Points
1 Post
AJAX password strength control - how to check for pass/fail?
Dec 07, 2007 02:16 PM|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?
Thanks!
Jonathan She...
All-Star
31269 Points
3445 Posts
Re: AJAX password strength control - how to check for pass/fail?
Dec 13, 2007 08:29 AM|LINK
Hi RTM1973,
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"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> <style> .BarIndicator_TextBox2_weak { color:Red; background-color:Red; } .BarIndicator_TextBox2_average { color:Blue; background-color:Blue; } .BarIndicator_TextBox2_good { color:Green; background-color:Green; } .BarBorder_TextBox2 { border-style:solid; border-width:1px; padding:2px 2px 2px 2px; width:200px; vertical-align:middle; } </style> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:TextBox ID="TextBox2" Width="150" TextMode="Password" runat="server" autocomplete="off" onkeypress="getPasswordStrengthState()" /><br /> <asp:Label ID="TextBox2_HelpLabel" runat="server"/><br /> <br /> <ajaxToolkit:PasswordStrength ID="PasswordStrength2" BehaviorID="myPSBID" runat="server" TargetControlID="TextBox2" DisplayPosition="RightSide" StrengthIndicatorType="BarIndicator" PreferredPasswordLength="15" HelpStatusLabelID="TextBox2_HelpLabel" StrengthStyles="BarIndicator_TextBox2_weak;BarIndicator_TextBox2_average;BarIndicator_TextBox2_good" 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"/> <script type="text/javascript" language="javascript"> function getPasswordStrengthState(){ if( $find("myPSBID")._getPasswordStrength()>50){ $get("<%=Button1.ClientID%>").style.display = ''; } } </script> </form> </body> </html>I have tested on IE7 & Firefox 2.0 . I'm using AJAX Control Toolkit V11119.
Best regards,
Jonathan
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
howiem
Member
108 Points
96 Posts
Re: AJAX password strength control - how to check for pass/fail?
Jul 23, 2009 08:57 PM|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
and
passwordstrength.CurrentStrength
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.
Howie
howiem
Member
108 Points
96 Posts
Someone please ADD this feature....
Jul 23, 2009 09:08 PM|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).