asp.net登录验证数据库

string name = TextBox1.Text;//赋值为前端输入的用户名
string pwd = TextBox2.Text;//赋值为前端输入的密码
string code = tbx_yzm.Text;//验证码
HttpCookie htco = Request.Cookies["ImageV"];
string scode = htco.Value.ToString();
try {
if (name != "" && pwd != "" && code != "")
{
string sql = string.Format("select * from AndUser where name='{0}’and pwd='{1}’", name, pwd);
List<AndUser> list = AndUserDAL.select(sql);
if (list.Count > 0)
{
Response.Write("<script>alert(‘登录成功’);location.href=’Home.aspx’;</script>");
}else
{
Response.Write("<script>alert(‘您还未注册该用户!’)</script >");
TextBox1.Text = "";
TextBox2.Text = "";
tbx_yzm.Text = "";
}

 }else if (name == "" && pwd == "" && code == "") { Response.Write("<script>alert('账号密码不能为空!')</script >"); TextBox1.Text = ""; TextBox2.Text = ""; tbx_yzm.Text = ""; }else if (code.ToUpper() != scode) { Response.Write("<script>alert('验证码输入不正确!')</script>"); }else { Response.Write("<script>alert('数据异常')</script >"); } } catch (Exception) { Response.Write("<script>alert('数据异常')</script >"); }

原文链接:https://q.cnblogs.com/q/139390/

更多内容