【ADO.NET基础-Regidter】简单的账户注册界面和源代码(可用于简单面试基础学习用)
2024-09-01 09:25:37
在阅读时如有问题或者建议,欢迎指出和提问,我也是初学者.........
前台代码:
<!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); }
}
}
界面截图:
最新文章
- css3 linear-gradient实现页面加载进度条效果
- *HDU1455 DFS剪枝
- Ansible简介
- Java I/O Basic
- udev/raw/asmlib/多路径 配置asm
- 【转】winform退出代码:Application.Exit和Environment.Exit(0)
- java@ LinkedList 学习
- hibernate查询显示参数
- js中使用控件名和数组下标方式获取控件的值时失败
- page分页类
- SAP资产折旧,消息编号AA687:在上一年结算之后您只能记帐到新的一年
- GIT入门笔记(20)- 使用eclipse 基于 git 开发过程梳理
- java jdk jre
- java锁
- iOS模拟器:Undefined symbols for architecture x86_64
- Linux常用性能工具功能、用法及原理(一)
- 【译】第二篇 SQL Server安全验证
- 在linux系统下运行jar包的命令如下
- ubuntu16.4菜单栏不见,终端不见解决方法
- String特殊值的判断方式
热门文章
- .NET Core ASP.NET Core Basic 1-2 控制反转与依赖注入
- effective java 3th item1:考虑静态工厂方法代替构造器
- xcode7中搭建python开发环境
- CodeForces - 534B-Covered Path+思路
- github 授权登录教程与如何设计第三方授权登录的用户表
- webstorm 突然不能用了?解决办法~
- 2019icpc南昌网络赛_I_Yukino With Subinterval
- Pandas Python For Data Science
- Fortify安全漏洞一般处理方法
- windows 服务 安装、卸载