📄 presslogin.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Cryptography;
using System.Data.SqlClient;
/// <summary>
/// pressLogin 的摘要说明
/// </summary>
public partial class pressLogin : System.Web.UI.Page
{
public pressLogin()
{
}
private string getMd5(string userPWD)
{
string str=null ;
string strC = null;
string strP = null;
byte[] arrHashInput;
byte[] arrHashOutput;
MD5CryptoServiceProvider objMD5;
strP = userPWD ;
strC = Session ["valStr"].ToString().Trim();
objMD5 = new MD5CryptoServiceProvider();
arrHashInput = Convert2ByteArray(strP +strC);
arrHashOutput = objMD5.ComputeHash(arrHashInput);
str = BitConverter.ToString(arrHashOutput);
str = str.Replace("-", "").ToLower();
return str;
}
private byte[] Convert2ByteArray(string strInput)
{
int intCounter;
char[] arrChar;
arrChar = strInput.ToCharArray();
byte[] arrByte = new byte[arrChar.Length];
for (intCounter = 0; intCounter <= arrByte.Length - 1; intCounter++)
arrByte[intCounter] = Convert.ToByte(arrChar[intCounter]);
return arrByte;
}
#region
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
/// <summary>
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public static string SelectTable(string sqlQuery)
{
string userPWD=null ;
SqlDataReader reader = null;
string strConn = "Initial Catalog = shopping; Data Source=127.0.0.1; Integrated Security=true";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sqlQuery;
cmd.CommandType = CommandType.Text;
reader = cmd.ExecuteReader();
if ( reader.HasRows !=false )
{
reader.Read();
userPWD = reader["userPassWorld"].ToString();
}
conn.Close();
return userPWD ;
}
protected void Page_Load(object sender, EventArgs e)
{
string md5 = null;
string userPWD = null;
string str = Request.Params["userName"].ToString().Trim();
string sqlstr = "select userPassWorld from UserTab where userName='" + str + "'";
userPWD=SelectTable(sqlstr ).Trim();
md5 = getMd5(userPWD );
string checkCode = Request.Params["userPWD"].ToString();
if (md5.Equals(checkCode))
{
this.Label1.Text = "登陆成功";
}
else
{
this.Label1.Text = "输入错误,请重新输入";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -