编程 .Net 用户验证登陆

来源:百度知道 编辑:UC知道 时间:2024/06/01 02:09:38
谁能帮忙写个.net调用SQL里面数据的用户名验证登陆程序,程序的主要功能是验证在网页中输入的帐号和密码是否和数据库中的一致,一致就实现登陆,不一致则提示错误,帐号和密码为空的时候也提示错误,请高手帮忙!!!!!!
我想通过if判断文本框里的内容来实现身份验证
主要是因为其中的细节我不会写,2年没写过了,都忘的差不多了

我自己项目里的东西(用户密码存储的是MD5加密后的字符串)

……
using System.Data.SqlClient;

protected void Button1_Click(object sender, EventArgs e)
{
string Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text.Trim(), "MD5"); //给用户密码加密

SqlConnection Conn =.....;
Conn.Open();
string query = "select * from users where Name='" + TextBox1.Text.Trim() + "'and Psw='" + Pwd + "'";
SqlCommand Cmd = new SqlCommand(query, Conn);
Cmd.ExecuteNonQuery();
SqlDataReader Dr = Cmd.ExecuteReader();

if (TextBox1.Text.Trim()!="" && TextBox2.Text.Trim() != "")
{
if (Dr.Read())
{
if (Dr["Psw"].ToString() == Pwd)
{
Session["Name"] = TextBox1.Text.Trim();
Session.Timeout = 20;
Dr.Close();
Conn.Close();
}
else
{
Response.Write("<script>ale