ASP.NET验证码控件-AutoAuthCode v1.5

来源:互联网 发布:淘宝网买四轮电动车 编辑:程序博客网 时间:2024/05/01 09:10
控件特点:
  1、使用方便,只需要从工具栏直接拖到页面即可自动验证。
  2、可自动完成客户端以及服务器的验证码验证,Ajax验证,随用户输入即时
     验证并友好提示。
  3、不影响页面运行。
  4、同一页面可以使用多个验证码控件,不冲突。
  5、可自定义验证码图片外观、可更改输入框外观。
  6、有水平方向垂直方向两种方式选择。
  7、有数字、小写字母、大写字母三种及任意两种组合、三种组合字符选择。
  8、兼容IE及FireFox。

 

控件及安装文件下载:

/Files/jhxk/Other/AutoAuthCode.rar

 

使用方法:
  先解压下载的压缩文件,压缩包包括如下文件:
    test文件夹(示例代码)
    ini.ini
    log.txt
    使用说明.txt
    安装.exe
    Vincent.AutoAuthCode.dll
    Vincent.WebConfigManager.dll
 
  如果有打开MS Visual Studio,请先关闭。然后打开“安装.exe”,注册及添加控件到工具箱,
再打开MS Visual Studio,展开“工具箱”,即可看到已添加“AuthCode”的控件,直接拖到aspx
页面。在.cs后台页面加入代码 if (AuthCode1.IsMatch){//验证后操作} 即可。
  也可以不安装,直接引用Vincent.AutoAuthCode.dll以及Vincent.WebConfigManager.dll文件即可。
  另外,需要在web.config里面的system.web/httpHandlers配置节点下添加如下配置:<add type="Vincent.AutoAuthCode.AuthCode,Vincent.AutoAuthCode, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b633909bc009d6d9" verb="GET" path="AuthCode_Image.ashx" validate="false" />(如果是在工具箱里面直接添加,则可以自动生成)
  
  详细见后面的示例代码。



控件说明:
  1、属性。
       IsMatch:指示用户输入的验证码是否正确
       TextControlWidth:文本框控件宽度
       NextImgText:提示更换图片信息,该提示信息同时显示于图片上面及图片左边
       IsShowNextImgText:是否在图片左边显示提示更换图片信息
       EnableNextImgText:是否充许换一张图片
       ErrorShowType:验证码错误显示方式
       CodeStringType:验证码字符类型,组合枚举值,例如CodeStringTypes.Number|CodeStringTypes.LowerLetter
       CodeStringLength:验证码字符长度,最少为4
       ImageType:验证码图像类型
       IsMatchCase:验证码验证时是否区分大小写
       LayoutDirection":控件各部分排列方向,排列的部分包括文本框、图片、"换一张图片"文本
       EnableClientValidate:是否使用客户端脚本验证,验证内容包括是否为空、长度是否正确
       ImageStyle:验证码图像样式
       SubmitControlID:客户端验证时,提交的按钮,点击该控件时,如果验证码不对,将不能提交,也不能回调。在EnableClientValidate为true时才有效。
       IsChangeImageOnPostback:回调时是否重新更改图像
       TextBoxClass:文本框样式,对应于 input type="text" 中的 class
       NextImgTextClass:换一张图片提示信息的样式
       TextBoxClientID:文本框客户端ID,只读
       SessionKey:当前验证码记录的Session Key,只读
 
       其中ImageStyle为复类属性,其公开属性如下:
         ImageStyle.ImgBgColor:图片背景色
         ImageStyle.ImgNoiseColor:图片噪声颜色
         ImageStyle.ImgBorderColor"图片边框颜色
         ImageStyle.TextColor1:文本颜色
         ImageStyle.TextColor2:文本颜色2(如果文本为单色则无效)
         ImageStyle.TextFontSize:文本字体大小,以像素(pix)为单位,验证码图像大小根据此而变化,如果ImgSize大于由该值指定的大小,则图像大小为ImgSize
         ImageStyle.ImgSize:验证码图像大小,以像素(pix)为单位,如果TextFontSize指定的大小大于该值,则图像大小为TextFontSize指定的大小
         ImageStyle.Width:验证码图像大小的宽度,以像素(pix)为单位,如果TextFontSize指定的大小大于该值,则图像大小为TextFontSize指定的大小
         ImageStyle.Height:验证码图像大小的高度,以像素(pix)为单位,如果TextFontSize指定的大小大于该值,则图像大小为TextFontSize指定的大小
         
  2、方法。
       1) public void ClearSession():
           清除在验证码中用到的Session。
       2)public virtual Bitmap GetBitmap(string codeText, ImageStyle imgStyle):
           获取验证码图像。在继承的类中可重载该方法,以自定义绘制图片。
           参数说明:
           string codeText:控件自动生成的验证码,该字符串显示于图片中。
           ImageStyle imgStyle:图片样式。
 
使用示例1-有客户端验证:
==============================示例1开始==============================
<%@ Page Language="C#" %>
 
<%@ Register Assembly="Vincent.AutoAuthCode, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b633909bc009d6d9"
    Namespace="Vincent.AutoAuthCode" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (AuthCode1.IsMatch)
        {
            ClientScript.RegisterStartupScript(GetType(), "authResult", "alert(\"验证码输入正确!\");", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "authResult", "alert(\"验证码输入错误!\");", true);
        }
    }
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <style type="text/css">
    .authText
    {
        background-color:#ffee88;
        border:1px solid #aa6600;
        width:200px;
    }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <cc1:AuthCode ID="AuthCode1" runat="server" TextBoxClass="authText" EnableClientValidate="true"
            SubmitControlID="btnLogin" />
        <br />
        <asp:Button ID="btnLogin" runat="server" Text="登 陆" OnClick="btnLogin_Click" />&nbsp;
    </form>
</body>
</html>
==============================示例1结束==============================
 
 
使用示例2-无客户端验证:
==============================示例2开始==============================
<%@ Page Language="C#" %>
 
<%@ Register Assembly="Vincent.AutoAuthCode, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b633909bc009d6d9"
    Namespace="Vincent.AutoAuthCode" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (AuthCode1.IsMatch)
        {
            ClientScript.RegisterStartupScript(GetType(), "authResult", "alert(\"验证码输入正确!\");", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "authResult", "alert(\"验证码输入错误!\");", true);
        }
    }
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
        <cc1:AuthCode ID="AuthCode1" runat="server" CodeStringLength="6" EnableClientValidate="False" CodeStringType="NumberAndLeter"
            ImageStyle-TextFontSize="30" ImageType="SimpleNoiseLine" LayoutDirection="Vertical" />
        <br />
        <asp:Button ID="btnLogin" runat="server" Text="登 陆" OnClick="btnLogin_Click" />&nbsp;
    </form>
</body>
</html>
0 0
原创粉丝点击