protected void imgBtnModifyPwd_Click1(object sender, ImageClickEventArgs e) { Usersmr user = new Usersmr();//����Usersmr����user user.LoadData(Session["userID"].ToString()); // string txtOldPwdMD5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtOldPwd.Text.Trim(), "MD5").ToString(); string txtOldPwdMD5 = user.GetMd5(txtOldPwd.Text.Trim()); if (user.UserPwd == txtOldPwdMD5)//��֤�û�����ԭ�����Ƿ���ȷ { // string txtNewPwdMD5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtNewPwd.Text.Trim(), "MD5").ToString(); string txtNewPwdMD5 = user.GetMd5(txtNewPwd.Text.Trim()); user.UserPwd = txtNewPwdMD5.ToString().Trim(); if (user.ModifyPassword(this.Session["userID"].ToString()))//�����û����� { lblMessage.Text = "�ɹ�������!"; } else//������ʧ�� { lblMessage.Text = "������ʧ��!"; } } else//ԭ������� { lblMessage.Text = "����ԭ�������,����������!"; } }
protected void imgBtnModifyPwd_Click1(object sender, ImageClickEventArgs e) { Usersmr user = new Usersmr();//创建Usersmr对象user user.LoadData(Session["userID"].ToString()); //string txtOldPwdMd5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtOldPwd.Text.Trim(), "MD5").ToString(); string txtOldPwdMd5 = user.GetMd5(txtOldPwd.Text.Trim()); if (user.UserPwd == txtOldPwdMd5)//验证用户输入原密码是否正确 { //string txtNewPwdMD5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtNewPwd.Text.Trim(), "MD5").ToString(); string txtNewPwdMD5 = user.GetMd5(txtNewPwd.Text.Trim()); user.UserPwd = txtNewPwdMD5; if (user.ModifyPassword(this.Session["userID"].ToString()))//更改用户密码 { lblPwd.Text = "成功修改密码!"; } else//修改密码失败 { lblPwd.Text = "修改密码失败!"; } } else//原密码错误 { lblPwd.Text = "输入原密码错误,请重新输入!"; } }
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { if (Page.IsValid) { Usersmr user = new Usersmr(); //创建Usersmr对象 user.UserID = txtUserID.Text.Trim(); if (!user.CheckUser(user.UserID)) //使用CheckUser方法验证用户是否存在 { user.UserName = txtUserName.Text; //原Md5加密很容易破解 //string PwdMD5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtUserPwd.Text.Trim(), "MD5").ToString(); //自定义的GetMd5加密方法可以实现无破解 string PwdMD5 = user.GetMd5(txtUserPwd.Text.ToString()); user.UserPwd = PwdMD5; user.DepartmentId = Convert.ToInt16(ddlDepartment.SelectedValue); user.RoleId = Convert.ToInt16(ddlRole.SelectedValue); if (user.InsertByStr()) { lblMessage.Text = "成功插入该用户信息!"; Server.Transfer("UserManage.aspx"); } else { lblMessage.Text = "添加用户失败!"; } } else//用户存在,给出提示 { lblMessage.Text = "数据库中存在具有该编号的用户,请重新输入!"; } } }
protected void ImageButtonResetPassword_Click(object sender, ImageClickEventArgs e) { int numOfChecked = 0; for (int i = 0; i < this.GridView1.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView1.Rows[i].FindControl("chkSelected")).Checked; if (isChecked) { numOfChecked++; } } if (numOfChecked == 1) { for (int i = 0; i < this.GridView1.Rows.Count; i++) { bool isChecked = ((CheckBox)GridView1.Rows[i].FindControl("chkSelected")).Checked; if (isChecked) { string UserID = ((Label)GridView1.Rows[i].FindControl("Label1")).Text; Random ran = new Random(); string newPassword = (ran.Next(999999).ToString().PadLeft(6, '8')); //随机生成一个密码 Usersmr user = new Usersmr(); //创建Usersmr对象user string pwdMd5 = user.GetMd5(newPassword); user.UserPwd = pwdMd5.ToString().Trim(); if (user.ModifyPassword(UserID))//更改用户密码 { Response.Write("<Script language=JavaScript>alert('" + UserID + "的密码已经重置,新密码为【" + newPassword + "】。');location='UserManage.aspx';</Script>"); } else//修改密码失败 { Response.Write("<Script language=JavaScript>alert('" + UserID + "重置密码失败!');location='UserManage.aspx';</Script>"); } } else { isChecked = false;//取消选中 } } } else { Response.Write("<Script language=JavaScript>alert('您只能选择一个用户!');;location='UserManage.aspx';</Script>"); return; } }
//登录按钮事件 protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e) { Usersmr user = new Usersmr();//创建Usersmr对象user //调用自定义GetMd5加密方法 string pwdMd5 = user.GetMd5(txtPwd.Text.ToString()); //判断验证码是否正确 if (Session["CheckCode"].ToString() != Validator.Text.Trim()) { //显示错误信息 lblMessage.Text = "验证码错误!"; } else { if (user.CheckPassword(txtUserID.Text.Trim())) //根据用户编号查询用户密码 { if (user.UserPwd == pwdMd5) //输入密码与用户密码相同 { if (object.Equals(Request.Cookies["UserID"], null)) { //调用自定义方法 CreateCookie()存储用户名 CreateCookie(); } else { CreateCookie(); } Session["userID"] = txtUserID.Text.Trim(); //存储用户编号 Response.Redirect("Default.aspx"); //转向管理员操作界面 } else//密码错误,给出提示 { lblMessage.Text = "您输入的密码错误!"; } } else//用户不存在,给出提示 { lblMessage.Text = "该用户不存在!"; } } }