添加-密码-加密
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Add.aspx.cs" Inherits="Add" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Data;
using System.Data.SqlClient;
public partial class Add : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//MD5 加密用户密码
public static string GetMD5(string str_data)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
Byte[] bytValue;
Byte[] bytText;
bytValue = System.Text.Encoding.UTF8.GetBytes(str_data);
bytText = md5.ComputeHash(bytValue);
return Convert.ToBase64String(bytText);
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=.;database=cs;uid=sa;pwd=");
conn.Open();
string sql_str = "INSERT INTO login_user (txtuser,txtpassword) VALUES ('"+TextBox1.Text+"', '"+GetMD5(TextBox2.Text)+"')";
SqlCommand cmd = new SqlCommand(sql_str,conn);
cmd.ExecuteNonQuery();
}
}

登陆的时候,把密码加密再去比对。
浙公网安备 33010602011771号