asp.net做登陆时,密码文本框输入值与数据库中的值匹配,为什么数据库的值和输入的值相同就是匹配不了?
asp.net做登陆时,对密码文本框输入的值与数据库中的值做匹配,为什么从数据库的中得到值和输入的值完全相同还是匹配不了呢?以下是Ui层代码protectedvoidbt...
asp.net做登陆时,对密码文本框输入的值与数据库中的值做匹配,为什么从数据库的中得到值和输入的值完全相同还是匹配不了呢?以下是Ui层代码
protected void btnLogin_Click(object sender, EventArgs e)
{
if (!CheckCode())//判断验证码是否正确
{
return;
}
string txtName = this.txtLoginName.Text.Trim();
string txtPass = this.txtLoginPwd.Text.Trim();
BLL.Folder.UserInfo bll = new BLL.Folder.UserInfo();
string msg = string.Empty;
Model.Folder.UserInfo model = null;
string ps = bll.getpassword(txtName, model);
bool b = bll.checkLogin(txtName, txtPass, out msg, out model);
if (b)
{
Session["UserName"] = model;
Response.Redirect("/ShowMsg.aspx?msg=" + Server.UrlEncode(msg) + "&url=../Default.aspx" + "&txt=" + Server.UrlEncode("跳到首页!"));
}
else
{
Response.Redirect("/ShowMsg.aspx?msg=" + Server.UrlEncode(msg) + "&url=Member/Login.aspx" + "&txt=" + Server.UrlEncode("跳转到登陆页!"));
}
}
//以下是BLL层代码
public bool checkLogin(string txtName, string txtPass, out string msg, out Model.Folder.UserInfo model)
{
model = dal.GetModel(txtName);
if (model != null)
{
if (model.UserStateId.Name == "正常")
{
if (model.LoginPwd== txtPass)
{
msg = "登陆成功";
return true;
}
else
{
msg = "用户名密码错误";
return false;
}
}
else
{
msg = "此用户已经被锁定";
return false;
}
}
else
{
msg = "此用户不存在";
return false;
}
}
}
//Dll层是根据代码生成器生成的,然后修改为GetModel(int ID方法做一个传用户名的重载GetModel(string LoginID) 展开
protected void btnLogin_Click(object sender, EventArgs e)
{
if (!CheckCode())//判断验证码是否正确
{
return;
}
string txtName = this.txtLoginName.Text.Trim();
string txtPass = this.txtLoginPwd.Text.Trim();
BLL.Folder.UserInfo bll = new BLL.Folder.UserInfo();
string msg = string.Empty;
Model.Folder.UserInfo model = null;
string ps = bll.getpassword(txtName, model);
bool b = bll.checkLogin(txtName, txtPass, out msg, out model);
if (b)
{
Session["UserName"] = model;
Response.Redirect("/ShowMsg.aspx?msg=" + Server.UrlEncode(msg) + "&url=../Default.aspx" + "&txt=" + Server.UrlEncode("跳到首页!"));
}
else
{
Response.Redirect("/ShowMsg.aspx?msg=" + Server.UrlEncode(msg) + "&url=Member/Login.aspx" + "&txt=" + Server.UrlEncode("跳转到登陆页!"));
}
}
//以下是BLL层代码
public bool checkLogin(string txtName, string txtPass, out string msg, out Model.Folder.UserInfo model)
{
model = dal.GetModel(txtName);
if (model != null)
{
if (model.UserStateId.Name == "正常")
{
if (model.LoginPwd== txtPass)
{
msg = "登陆成功";
return true;
}
else
{
msg = "用户名密码错误";
return false;
}
}
else
{
msg = "此用户已经被锁定";
return false;
}
}
else
{
msg = "此用户不存在";
return false;
}
}
}
//Dll层是根据代码生成器生成的,然后修改为GetModel(int ID方法做一个传用户名的重载GetModel(string LoginID) 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询