为什么登陆时总显示密码错误,密码与数据库内的完全一致啊
我的确是菜鸟,希望高手帮我解决下,谢谢 以下是 登陆的login.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 OnLineExam.BusinessLogicLayer;
public partial class Web_Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!Object.Equals(Request.Cookies["UserID"], null))
{
HttpCookie readcookie = Request.Cookies["UserID"];
this.txtUserID.Text = readcookie.Value;
}
}
}
//登录按钮事件
protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e)
{
Users user = new Users();//创建Users对象user
string pwdMd5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtPwd.Text.Trim(), "MD5").ToString();
if (String.Compare(Request.Cookies["yzmcode"].Value, Validator.Text, true) != 0)
{
lblMessage.Text = "验证码错误!";
}
else
{
if (user.CheckPassword(txtUserID.Text.Trim()))//根据用户编号查询用户密码
{
if (user.UserPwd == pwdMd5)//输入密码与用户密码相同
{
if (object.Equals(Request.Cookies["UserID"], null))
{
CreateCookie();
}
else
{
CreateCookie();
}
Session["userID"] = txtUserID.Text.Trim();//存储用户编号
Response.Redirect("Default.aspx");//转向管理员操作界面
}
else//密码错误,给出提示
{
lblMessage.Text = "您输入的密码错误!";
}
}
else//用户不存在,给出提示
{
lblMessage.Text = "该用户不存在!";
}
}
}
protected void ChangeCode_Click(object sender, EventArgs e)
{
}
private void CreateCookie()
{
HttpCookie cookie = new HttpCookie("UserID");
if (this.cbxRemeberUser.Checked)
{
cookie.Value = this.txtUserID.Text;
}
cookie.Expires = DateTime.MaxValue;
Response.AppendCookie(cookie);
}
}