在阅读时如有问题或者建议,欢迎指出和提问,我也是初学者.........

前台代码:

<!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="lblName" runat="server">姓名:</asp:Label>
<asp:TextBox ID="txtName" 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="lblText" runat="server" Text=""></asp:Label></p>
<p> <asp:Button ID="btnRegister" runat="server" Text="注册" onclick="btnRegister_Click" />
</p> </form>
</div>
</body>
</html>

后台代码:

using System;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Drawing;
using System.Text;
using System.Security.Cryptography; namespace ado.netDemo1
{
public partial class register : System.Web.UI.Page
{
SqlConnection connStr = new SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ToString());
string sql;
protected void Page_Load(object sender, EventArgs e)
{
} protected void btnRegister_Click(object sender, EventArgs e)
{
if (txtNum.Text.Trim() == "" || txtName.Text.Trim() == "" || txtpwd.Text.Trim() == "")
{
lblText.ForeColor = Color.Red;
lblText.Text = "请将个人信息填写完整!";
}
else if (txtNum.Text.Trim() == "" && txtName.Text.Trim() == "" && txtpwd.Text.Trim() == "")
{
lblText.ForeColor = Color.Red;
lblText.Text = "请将个人信息填写完整!";
}
else
{
//加密处理注册Password
string hashedpwd=Encrypt(txtpwd.Text.Trim());
sql = "insert into tb_Students(SID,Name,Password)Values('" + txtNum.Text.Trim() + "','" + txtName.Text.Trim() + "','" + hashedpwd + "')";
connStr.Open();
SqlCommand cmd = new SqlCommand(sql, connStr);
int i = cmd.ExecuteNonQuery();
if (i == )
{
lblText.ForeColor = Color.Red;
lblText.Text = "注册成功!";
Response.Write(@"<script>window.alert('请到登陆界面登陆!');window.location='Login.aspx'</script>");
}
}
} public static string Encrypt(string cleanString)
{
Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes); }
}
}

界面截图:

最新文章

  1. css3 linear-gradient实现页面加载进度条效果
  2. *HDU1455 DFS剪枝
  3. Ansible简介
  4. Java I/O Basic
  5. udev/raw/asmlib/多路径 配置asm
  6. 【转】winform退出代码:Application.Exit和Environment.Exit(0)
  7. java@ LinkedList 学习
  8. hibernate查询显示参数
  9. js中使用控件名和数组下标方式获取控件的值时失败
  10. page分页类
  11. SAP资产折旧,消息编号AA687:在上一年结算之后您只能记帐到新的一年
  12. GIT入门笔记(20)- 使用eclipse 基于 git 开发过程梳理
  13. java jdk jre
  14. java锁
  15. iOS模拟器:Undefined symbols for architecture x86_64
  16. Linux常用性能工具功能、用法及原理(一)
  17. 【译】第二篇 SQL Server安全验证
  18. 在linux系统下运行jar包的命令如下
  19. ubuntu16.4菜单栏不见,终端不见解决方法
  20. String特殊值的判断方式

热门文章

  1. .NET Core ASP.NET Core Basic 1-2 控制反转与依赖注入
  2. effective java 3th item1:考虑静态工厂方法代替构造器
  3. xcode7中搭建python开发环境
  4. CodeForces - 534B-Covered Path+思路
  5. github 授权登录教程与如何设计第三方授权登录的用户表
  6. webstorm 突然不能用了?解决办法~
  7. 2019icpc南昌网络赛_I_Yukino With Subinterval
  8. Pandas Python For Data Science
  9. Fortify安全漏洞一般处理方法
  10. windows 服务 安装、卸载