/// <summary> /// 登录 /// </summary> /// <param name="name">用户名</param> /// <param name="pwd">密码</param> /// <param name="Session">用户信息缓存</param> /// <returns><验证结果/returns> public byte Login(string name, string pwd) { using (DataSubmittedEntities db = new DataSubmittedEntities()) { //查找数据库中用户名匹配的记录 List<OT_User> list = db.OT_User.Where(a => a.Name == name).ToList(); //存在该用户名 if (list != null && list.Count > 0) { //对密码进行加密 MD5Encryptor md5 = new MD5Encryptor(); string password = md5.Encrypt(pwd); //密码比对 if (list[0].Password == password) { //检查状态 if (list[0].IsDelete == (byte)EUserStatus.Normal) { SaveUserInfo(list[0].Id); return (byte)ELoginResult.Succeed; } else { return (byte)ELoginResult.IsDelete; } } else { return (byte)ELoginResult.PasswordError; } } else { return (byte)ELoginResult.NameInexist; } } }
/// <summary> /// 修改密码 /// </summary> /// <param name="userId">用户编号</param> /// <param name="pwd">新密码</param> /// <param name="oldpwd">旧密码</param> /// <returns>修改结果</returns> public CustomResult UpdatePassword(Guid userId, string pwd, string oldpwd) { using (DataSubmittedEntities db = new DataSubmittedEntities()) { using (TransactionScope transaction = new TransactionScope()) { MD5Encryptor md5 = new MD5Encryptor(); string password = md5.Encrypt(oldpwd); var list = db.OT_User.Where(a => a.Id == userId & a.Password == password & a.IsDelete == (byte)EUserStatus.Normal).ToList(); if (list != null && list.Count > 0) { password = md5.Encrypt(pwd); foreach (var info in list) { info.Password = password; } SessionManage.SetSession("UserInfo", null); return Result.SaveUpdateResult(db, transaction); } else { CustomResult pReturnValue = new CustomResult(); pReturnValue.ResultKey = (byte)EResult.Fail;//程序已经使用多处,所有不变动 pReturnValue.ResultValue = Wttech.DataSubmitted.Common.Resources.TipInfo.OldPasswordError; return pReturnValue; } } } }