关于 ASP.NET 验证码

 1 ValidateCode.ashx 验证码文件,这是一个文件。。我想给大家上传上。。。但是没找到上传在哪。。。
2 Session["CheckCode"] 这个。。不懂神马意思。。 3 1.创建一个用户控件 4 用户名:TextBox 5 密码: TextBox 6 验证码:TextBox 验证码图片 7 8 <p> 9 验证码:<asp:TextBox ID="txt" runat="server"></asp:TextBox> 10 <img alt="验证码" src="/ValidateCode.ashx" title="看不清,换一张" οnclick="Changeimg(this)" style="cursor:pointer" /> 11 12 <script type="text/javascript"> //换图片的单机事件 13 function Changeimg(img) { 14 img.src = "ValidateCode.ashx?id=" + new Date(); 15 } 16 </script> 17 </p> 18 2.因为用户控件不允许直接用URL访问,所以把用户控件拖到aspx上面 19 btnSubmit 单击事件 20 21 protected void btnSubmit_Click(object sender, EventArgs e) 22 { 23 if (!string.IsNullOrEmpty(txtVerify.Text.Trim())) //如果不为空 24 { 25 if (Session["CheckCode"].ToString().ToLower().Equals(txtVerify.Text.Trim())) //验证码与文本框比较是否相等 26 { 27 //Response.Write("<script>alert('验证成功')</script>"); 28 string _user = txtUser.Text.Trim(); 29 string _pwd = txtPwd.Text.Trim(); 30 string sql = string.Format("SELECT * FROM TREE WHERE City='{0}' AND ID='{1}'",_user,_pwd); 31 int result = new BStudentInfo().GetSutdentInfo(sql);//数据库查询
32 if (result > 0) 33 { 34 Response.Redirect("TreeView.aspx"); //数据库验证和验证码输入正确之后跳转到"TreeView.aspx"页面 35 } 36 } 37 else 38 { 39 Response.Write("<script>alert('登录失败')</script>"); 40 } 41 } 42 43 }

我感觉学的可迷糊了。。有时候都觉得在背代码。。。。哎。。好好加油~~

世界晚安


 

转载于:https://www.cnblogs.com/bydongxin/p/3560253.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值