ASP.NET使用MD5加密用户验证
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://zhcsmx22.blog.51cto.com/287943/58718 |
using System.Data.SqlClient; using System.Configuration; using System.Web.Configuration; using System.Security.Cryptography; using System.Text; 代码部分:
protected void Button1_Click(object sender, EventArgs e) { //建立数据库连接 string ConnString = WebConfigurationManager.ConnectionStrings["ABCDWebConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(ConnString); //创建数据库命令 string sql; sql = "Select COUNT(*) From Users Where UName=@Username and PassW=@Password"; SqlCommand Comm = new SqlCommand(sql, conn); //重建用户名验证 SqlParameter Username = new SqlParameter("@Username", SqlDbType.NChar, 50); Username.Value = TextBox1.Text; Comm.Parameters.Add(Username); MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); Byte[] hashedDataBytes; UTF8Encoding encoder = new UTF8Encoding(); hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBox2.Text)); string b = ""; for (int i = 0; i <= 15; ++i) { b += hashedDataBytes[i]; } SqlParameter Password = new SqlParameter("@Password", SqlDbType.NChar, 50); Password.Value = b; Comm.Parameters.Add(Password); conn.Open(); int j = Convert.ToInt16(Comm.ExecuteScalar()); conn.Close(); if (j == 1) { Label1.Text = "正确"; } else { Label1.Text = "错误"; } } 本文出自 “赵宏臣主页” 博客,请务必保留此出处http://zhcsmx22.blog.51cto.com/287943/58718 本文出自 51CTO.COM技术博客 |


using System.Data.SqlClient;
zhcsmx22
博客统计信息
热门文章
最新评论
友情链接