/// <summary> /// 修改密码或用户名时候调用。调用时password应该是加密前password /// </summary> /// <param name="db"></param> /// <returns></returns> public void Save(Context db, SystemUser newValue) { if (Id == 0) { db.SystemUsers.Add(this); } newValue.LoginName = newValue.LoginName.Trim(); if (LoginName != newValue.LoginName || string.IsNullOrEmpty(newValue.Password) == false) { LoginName = newValue.LoginName; Password = EncryptPassword(LoginName.ToLower(), newValue.Password); } Name = newValue.Name; Email = newValue.Email; State = newValue.State; db.SaveChanges(); //刷新缓存 UserBLL.Users = null; }
private void OK_Click(object sender, EventArgs e) { try { MYDBEntities2 myEntity = new MYDBEntities2(); this.DialogResult = System.Windows.Forms.DialogResult.OK; string LoginName, Password; LoginName = txtLoginName.Text.Trim(); Password = txtPassword.Text.Trim(); List <T_Users> Users = myEntity.T_Users.Where(d => d.LoginName == LoginName).ToList(); if (Users.Count < 1) { MessageBox.Show("登录名输入错误"); return; } else { var User = Users.FirstOrDefault(); Password = Classes.MD5.Md5Encrypt(Password); if (string.Compare(Password, User.PassWord) != 0) { MessageBox.Show("密码输入错误"); txtPassword.Text = ""; return; } if (User.UserStatus != "正常") { MessageBox.Show("该账户已停用"); return; } if (LoginName.ToLower() == "admin") { CommonClass.SttUser.blSuperUser = true; } else { CommonClass.SttUser.blSuperUser = false; } Classes.PubClass.LoginName = LoginName; Classes.PubClass.UserId = User.id; Classes.PubClass.UserName = User.UserName; Classes.PubClass.UserRight = User.OperRight; Classes.PubClass.UserStatus = User.UserStatus; Classes.PubClass.UserRoleId = User.IntRoleID ?? -1; //添加权限 CommonClass.UserRightList.Clear(); 销售管理.BLL.Da.GetUserRight(Classes.PubClass.UserRoleId); CommonClass.SttDb.iDBType = 1; isLogined = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } //var mTable = new T_UsersTableAdapter().GetDataByLoginName(LoginName); //if (mTable.Rows.Count < 1) //{ // MessageBox.Show("登录名输入错误"); // return; //} //else //{ // var mRow = (销售管理.DAL.DataSetUsers.T_UsersRow)mTable.Rows[0]; // Password = Classes.MD5.Md5Encrypt(Password); // if (string.Compare(Password, mRow.PassWord) != 0) // { // MessageBox.Show("密码输入错误"); // txtPassword.Text = ""; // return; // } // Classes.PubClass.LoginName = LoginName; // Classes.PubClass.UserId = mRow.id; // Classes.PubClass.UserName = mRow.UserName; // Classes.PubClass.UserRight = mRow.OperRight; // Classes.PubClass.UserStatus = mRow.UserStatus; // isLogined = true; //} System.Net.IPAddress[] IPs = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()); for (int c = 0; c < IPs.Length; c++) { if (IPs[c].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { new T_LoginLogTableAdapter().Insert(Classes.PubClass.UserId, IPs[c].ToString()); } } MainForm mForm = new MainForm(this); // mForm.tssb用户名.Text = "登录用户名:"+ Classes.PubClass.UserName +" | 权限:" + Classes.PubClass.UserRight; mForm.LoadModuleListFromDb(Classes.PubClass.UserRoleId); mForm.Show(); //this.DialogResult = DialogResult.OK; this.Hide(); }
private void OK_Click(object sender, EventArgs e) { //获取连接字符串 string file = System.Windows.Forms.Application.ExecutablePath; Configuration config = ConfigurationManager.OpenExeConfiguration(file); String xmlPath = "DBInfo.xml"; if (xmlPath == null) { MessageBox.Show("请先选择数据源!"); } Common.SqlConnectionSet.SetConnStr(xmlPath.Trim()); try { MYDBEntities2 myEntity = new MYDBEntities2(); this.DialogResult = System.Windows.Forms.DialogResult.OK; string LoginName, Password; LoginName = txtLoginName.Text.Trim(); Password = txtPassword.Text.Trim(); List <T_Users> Users = myEntity.T_Users.Where(d => d.LoginName == LoginName).ToList(); if (Users.Count < 1) { MessageBox.Show("登录名输入错误"); return; } else { var User = Users.FirstOrDefault(); Password = Classes.MD5.Md5Encrypt(Password); if (string.Compare(Password, User.PassWord) != 0) { MessageBox.Show("密码输入错误"); txtPassword.Text = ""; return; } if (User.UserStatus != "正常") { MessageBox.Show("该账户已停用"); return; } if (LoginName.ToLower() == "admin") { CommonClass.SttUser.blSuperUser = true; } else { CommonClass.SttUser.blSuperUser = false; } Classes.PubClass.LoginName = LoginName; Classes.PubClass.UserId = User.id; Classes.PubClass.UserName = User.UserName; Classes.PubClass.UserRight = User.OperRight; Classes.PubClass.UserStatus = User.UserStatus; Classes.PubClass.UserRoleId = User.IntRoleID ?? -1; //添加权限 CommonClass.UserRightList.Clear(); 销售管理.BLL.Da.GetUserRight(Classes.PubClass.UserRoleId); CommonClass.SttDb.iDBType = 1; isLogined = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } System.Net.IPAddress[] IPs = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()); for (int c = 0; c < IPs.Length; c++) { if (IPs[c].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { new T_LoginLogTableAdapter().Insert(Classes.PubClass.UserId, IPs[c].ToString()); } } MainForm mForm = new MainForm(this); //mForm.tssb用户名.Text = "登录用户名:"+ Classes.PubClass.UserName +" | 权限:" + Classes.PubClass.UserRight; mForm.LoadModuleListFromDb(Classes.PubClass.UserRoleId); mForm.Show(); //this.DialogResult = DialogResult.OK; this.Hide(); }
public void ChangePassword(Context db, string password) { Password = EncryptPassword(LoginName.ToLower(), password); db.SaveChanges(); }
public bool CheckPassword(string password) { return(Password == EncryptPassword(LoginName.ToLower(), password)); }