【ADO.NET基础-Login】带验证码验证的登录界面(用于简单的基础学习)
以下代码如果有不对或者不妥之处,还望大神们指点一二
或者有同学者有问题或建议,一定要提出来,共同探讨
小弟在此感谢!
前台代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div align="center">
<h1>用户登录页面</h1>
<form id="form1" runat="server">
<p> <asp:Label ID="lbusername" runat="server">学号:</asp:Label>
<asp:TextBox ID="txtNum" runat="server"></asp:TextBox>
</p> <p> <asp:Label ID="lbpsw" runat="server">密 码:</asp:Label>
<asp:TextBox ID="txtpwd" runat="server" TextMode="Password"></asp:TextBox>
</p>
<p> <asp:Label ID="lblyzm" runat="server">验证码:</asp:Label>
<asp:TextBox ID="txtYZM" runat="server" ></asp:TextBox>
<label id="lblcode" runat="server"><asp:ImageButton ID="ImageButton1" runat="server" Height="25px" Width="54px" /></label>
</p>
<p>
<asp:Label ID="lblText" runat="server" Text=""></asp:Label></p>
<p><asp:Button ID="btnLogin" runat="server" Text="登录" onclick="btnLogin_Click" /> </p> </form>
</div>
</body>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Text;
using System.Security.Cryptography; namespace ado.netDemo1
{
public partial class Login : System.Web.UI.Page
{
SqlConnection connStr = new SqlConnection( ConfigurationManager.ConnectionStrings["connStr"].ToString());
string sql;
protected void Page_Load(object sender, EventArgs e)
{
ImageButton1.ImageUrl = "~/picture.aspx"; } protected void btnLogin_Click(object sender, EventArgs e)
{
if (lblyzm.Text.Trim() == null)
{
lblText.ForeColor = Color.Red;
lblText.Text = "请输入验证码!";
}
else if (txtYZM.Text.Trim() != Session["CheckCode"].ToString())
{
lblText.ForeColor = Color.Red;
lblText.Text = "验证码错误,请重新填写!";
}
else
{
if ((txtNum.Text.Trim() == "") && (txtpwd.Text.Trim() == ""))
{
lblText.ForeColor = Color.Red;
lblText.Text = "请您输入用户名和密码!"; }
else if ((txtNum.Text.Trim() == "") || (txtpwd.Text.Trim() == ""))
{
lblText.ForeColor = Color.Red;
lblText.Text = "用户名或密码不正确!"; }
else
{
string hashedPWD = Encrypt(txtpwd.Text.Trim());
sql = "select * from tb_Students where SID='" + txtNum.Text.Trim() + "'and password='" +hashedPWD + "'";
connStr.Open();
SqlCommand cmd = new SqlCommand(sql, connStr);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["Username"] = dr.GetValue(dr.GetOrdinal("name"));
Response.Write(@"<script>window.alert('登录成功');window.location ='Test1.aspx'</script>");
}
}
}
connStr.Close(); }
public static string Encrypt(string cleanString)
{
Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes); return BitConverter.ToString(hashedBytes); } }
}
运行截图:

【ADO.NET基础-Login】带验证码验证的登录界面(用于简单的基础学习)的更多相关文章
- 【ADO.NET基础-Regidter】简单的账户注册界面和源代码(可用于简单面试基础学习用)
在阅读时如有问题或者建议,欢迎指出和提问,我也是初学者......... 前台代码: <!DOCTYPE html> <html xmlns="http://www.w3. ...
- easyui datagrid 禁止选中行 EF的增删改查(转载) C# 获取用户IP地址(转载) MVC EF 执行SQL语句(转载) 在EF中执行SQL语句(转载) EF中使用SQL语句或存储过程 .net MVC使用Session验证用户登录 PowerDesigner 参照完整性约束(转载)
easyui datagrid 禁止选中行 没有找到可以直接禁止的属性,但是找到两个间接禁止的方式. 方式一: //onClickRow: function (rowIndex, rowData) ...
- django 的用户验证及登录状态保持
一.用户验证功能 Django自带用户验证及登录功能,引入模块为: from django.contrib.auth import authenticate 其中方法authenticate()的接收 ...
- 基于控制权限和登录验证跳转的django登录界面的实现
django框架提供了出去登录和退出系统的login和logout的视图函数,本实现中使用系统自带的是视图函数.需要在settings.py,urls.py,views.py和模板文件等几个方面进行考 ...
- .net MVC使用Session验证用户登录(转载)
.net MVC使用Session验证用户登录 用最简单的Session方式记录用户登录状态 1.添加DefaultController控制器,重写OnActionExecuting方法,每次访问 ...
- Python 爬虫入门(四)—— 验证码上篇(主要讲述验证码验证流程,不含破解验证码)
本篇主要讲述验证码的验证流程,包括如何验证码的实现.如何获取验证码.识别验证码(这篇是人来识别,机器识别放在下篇).发送验证码.同样以一个例子来说明.目标网址 http://icp.alexa.cn/ ...
- yii2.0表单自带验证码
Yii2.0的自带的验证依赖于GD2或者ImageMagick扩展. 使用步骤如下: 第一步,控制器: 在任意controller里面重写方法
- 用HttpWebRequest提交带验证码的网站
using System; using System.Drawing; using System.IO; using System.Net; using System.Text; using Syst ...
- curl 模拟登录微信公众平台带验证码
这段时间一直写个项目, 从切图到前端到后台都要搞定,真tm累. 今天下午手残,不停用错误的密码去模拟登录微信公众平台,结果后来出现验证码,瞬间悲剧(菜鸟从来没搞过带验证码的). 研究了一下,发现其实很 ...
随机推荐
- hihocoder #1609 : 数组分拆II(思维)
题目链接:http://hihocoder.com/problemset/problem/1609 题解:就先拿一个数组最多分成两部分来说吧 8 1 2 3 4 5 1 2 3 显然 输出时2 3 可 ...
- Codeforces 939 D Love Rescue
Love Rescue 题意:Valya 和 Tolya 是一对情侣, 他们的T恤和头巾上都有小写字母,但是女朋友嫌弃男朋友上T恤上的字不和她的头巾上的字一样,就很生气, 然后来了一个魔法师, 它可以 ...
- codeforces 19 D. Points(线段树+set二分)
题目链接:http://codeforces.com/contest/19/problem/D 题意:给出3种操作:1)添加点(x,y),2)删除点(x,y),3)查询离(x,y)最近的右上方的点. ...
- CF 988E Divisibility by 25 思维 第十二
Divisibility by 25 time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 菜鸟系列Fabric——Fabric 动态添加组织(7)
Fabric 网络动态添加组织 1.环境准备 如果存在fabric网络环境可不执行,若不存在可以安装下列进行准备 下载fabric-sample,fabric https://github.com/h ...
- springmvc全局异常后返回JSON异常数据
转自:http://www.cnblogs.com/exmyth/p/5601288.html (1)自定义或者使用spring自带的各种异常处理器 例如spring基于注解的异常解析器Annotat ...
- if __name__ = "main" 解释
- Visual Studio 调试 —— 附加到进程(远程服务器)
一般在部署环境下不会有 Visual Studio 开发工具的,所以需要有 Remote Debugger(远程调试器) 才可以进行远程调试. Remote Debugger 获取 方法一:Visua ...
- Go语言标准库之log
无论是软件开发的调试阶段还是软件上线之后的运行阶段,日志一直都是非常重要的一个环节,我们也应该养成在程序中记录日志的好习惯. log Go语言内置的log包实现了简单的日志服务.本文介绍了标准库log ...
- Python3-编码问题-解决为何我的python打印总是出现乱码??
#python3 编码问题: ############举个例子############################### import sys print(sys.getdefaultencodi ...