验证登陆的函数:publicintcheckLogin(stringName,stringPwd){MySqlConnectionconn=newMySqlConnection("DataSource=localhost;Database=web;userid=root;");MySqlCommandmyCommand=n...
验证登陆的函数:
public int checkLogin(string Name, string Pwd)
{
MySqlConnection conn = new MySqlConnection("Data Source=localhost;Database=web;user id=root;");
MySqlCommand myCommand = new MySqlCommand("select count(*) from user1 where username='@Name' and userpassword='@pwd'", conn);//~5``1*a^s~p~x
myCommand.Parameters.Add(new MySqlParameter("@Name",MySqlDbType.VarChar,50));
myCommand.Parameters["@Name"].Value = Name;
myCommand.Parameters.Add(new MySqlParameter("@Pwd",MySqlDbType.VarChar,50));
myCommand.Parameters["@Pwd"].Value = Pwd;
myCommand.Connection.Open();
int i = Convert.ToInt32(myCommand.ExecuteScalar());
myCommand.Connection.Close();
return i;
}
后台调用:
if (ndb.checkLogin(textname.Text, textpass.Text) > 0)
{
//登陆成功
Response.Write("");
Response.Redirect("~/back/back.aspx");
}
else
{
Response.Write(ndb.MessageBox("用户名或密码错误!"));
}
用正确的用户名和密码登陆显示“用户名密码错误”
展开