gfreesky博客


    留下自己的脚印是一件很惬意的事:)
    博客园--美好愿望 美好生活......
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

AjaxControlTookit系列之PasswordStrength

Posted on 2008-10-26 12:12  gfreesky  阅读(772)  评论(0编辑  收藏  举报

今天要实现的是AjaxControlTookit的PasswordStrength功能,这个功能也很常见,相信大家也都见过或者也用过,就是以一种方式或者标准来验证这个密码的安全强度如何,实现的方法各一,这里只介绍PasswordStrength这个控件是如何实现的。

先看看效果图:

图1:


图2:


图3:

好下面开始,页面部分:

 

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
Simple Complexity, Text Indicator
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Label ID="Label1" runat="server" Height="19px" Text="Label" Width="153px"></asp:Label><br />
<br />
Average Complexity, Bar Indicator
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Height="20px" Text="Label" Width="153px"></asp:Label><br />
<br />
<br />
<br />
Help Indicator
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Label" Height="17px" Width="154px"></asp:Label><br />
<br />
<cc1:PasswordStrength ID="PasswordStrength1" runat="server" TargetControlID="TextBox1"
DisplayPosition
="rightSide" StrengthIndicatorType="Text" PreferredPasswordLength="10"
PrefixText
="Strength:" TextCssClass="TextIndicator_TextBox1" TextStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent"
MinimumNumericCharacters
="0" MinimumSymbolCharacters="0" HelpStatusLabelID="Label1"
RequiresUpperAndLowerCaseCharacters
="false">
</cc1:PasswordStrength>
<br />
<cc1:PasswordStrength ID="PasswordStrength2" runat="server" TargetControlID="TextBox2"
DisplayPosition
="rightSide" StrengthIndicatorType="BarIndicator" BarIndicatorCssClass="BarIndicator_TextBox2"
BarBorderCssClass
="BarBorder_TextBox2" PreferredPasswordLength="10" PrefixText="Strength:"
TextStrengthDescriptions
="Very Poor;Weak;Average;Strong;Excellent" MinimumNumericCharacters="1"
MinimumSymbolCharacters
="1" HelpStatusLabelID="Label2" RequiresUpperAndLowerCaseCharacters="true">
</cc1:PasswordStrength>
<br />
<cc1:PasswordStrength ID="PasswordStrength3" runat="server" TargetControlID="TextBox3"
TextCssClass
="TextIndictator_TextBox3" DisplayPosition="rightSide" StrengthIndicatorType="Text"
PreferredPasswordLength
="20" MinimumNumericCharacters="2" MinimumSymbolCharacters="2"
HelpStatusLabelID
="Label3" HelpHandlePosition="BelowRight" HelpHandleCssClass="TextIndicator_TextBox3_Handle"
PrefixText
="Metts Policy : " TextStrengthDescriptions="Not at All;Very Low compliance;Low Compliance;Average Compliance;Good Compliance;High Compliance;Fully Compliance">
</cc1:PasswordStrength>
<br />
</div>
</form>

其中的css样式设置如下
.TextIndicator_TextBox1
{
background
-color:Gray;
color:White;
font
-family:Arial;
font
-size:x-small;
font
-style:italic;
padding:2px 3px 2px 3px;
}
.BarIndicator_TextBox2_weak
{
color:Red;
background
-color:Red;
}
.BarIndicator_TextBox2_average
{
color:Blue;
background
-color:Blue;
}
.BarIndicator_TextBox2_good
{
color:Green;
background
-color:Green;
}
.BarIndicator_TextBox2
{
color:Blue;
background
-color:Blue;
height:20px;
}
.BarBorder_TextBox2
{
border
-style:solid;
border
-width:1px;
padding:
0;
width:200px;
vertical
-align:middle;
}
.TextIndictator_TextBox3
{
background
-color:Blue;
color:Yellow;
font
-size:small;
font
-variant:small-caps;
padding:2px 3px 2px 3px;
}
.TextIndicator_TextBox3_Handle
{
width:16px;
height:14px;
background
-image:url(../images/Question.png);
overflow:hidden;
cursor:help;
}

好了,设置完毕!
最后想提醒大家的是,我这里的ControlToolkit不是最新版本,所以css样式里的BarIndicator_TextBox2_weak、BarIndicator_TextBox2_average和BarIndicator_TextBox2_good都用不上,这些要ControlToolkit高版本才支持应该在VS2008--.NET3.5支持了,本人用的是VS2005-NET2.0