public CurrentUser CheckLogin(string username, string password) { var user = Query <User>(p => p.Account.Equals(username)).FirstOrDefaultAsync()?.Result; if (user == null) { throw new Exception("账户不存在,请重新输入"); } var dbPassword = Md5EncryptHelper.Encrypt(DESEncryptHelper.Encrypt(password.ToLower(), user.Secretkey).ToLower(), 32).ToLower(); if (dbPassword != user.Password) { throw new Exception("密码不正确,请重新输入"); } user.PreVisitTime = user.LastVisitTime.HasValue ? user.LastVisitTime : null; user.LastVisitTime = DateTime.Now; user.LoginCount = Convert.ToInt32(user.LoginCount) + 1; SaveChanges(); var cuser = user.MapTo <CurrentUser>(); cuser.LoginToken = DESEncryptHelper.Encrypt(Guid.NewGuid().ToString()); cuser.Ip = Net.Ip; cuser.IpLocation = Net.GetLocation(cuser.Ip); cuser.Roles = GetUserRoles(user.Id); if (cuser.Account == "admin") { cuser.DutyId = "admin"; cuser.IsSystem = true; } return(cuser); }
public ActionResult SubmitResetPassword(string password, string oldPassword, string verifyCode) { verifyCode = Md5Helper.Md5(verifyCode.ToLower()); string code = Session["session_verifycode"].ToString(); if (string.IsNullOrWhiteSpace(code) || verifyCode != code) { return(Error("验证码错误,请重新输入")); } string key = OperatorProvider.Provider.Current().Secretkey; oldPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(oldPassword, key).ToLower()).ToLower(); if (oldPassword != OperatorProvider.Provider.Current().Password) { return(Error("原密码错误,请重新输入")); } string md5 = Md5Helper.Md5(password); string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(md5, key)); userBLL.RevisePassword(OperatorProvider.Provider.Current().UserId, realPassword, key); Session.Abandon(); Session.Clear(); return(Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。")); }
public bool VerifyPwd(string userId, string password) { var user = Read <User>(p => p.Id.Equals(userId)).Select(p => new { p.Secretkey, p.Password }).FirstOrDefaultAsync().Result; var dbPassword = Md5EncryptHelper.Encrypt(DESEncryptHelper.Encrypt(password.ToLower(), user.Secretkey).ToLower(), 32).ToLower(); return(dbPassword == user.Password); }
/// <summary> /// 写入登录信息 /// </summary> /// <param name="user">成员信息</param> public virtual void AddCurrent(OperatorEntity user) { try { if (_loginProvider == "Cookie") { CookieHelper.WriteCookie(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson()), 60); } else if (_loginProvider == "Session") { SessionHelper.AddSession(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson()), 60, 0); } else if (_loginProvider == "Cache") { CacheFactory.GetCacheInstance().WriteCache(DESEncryptHelper.Encrypt(user.TryToJson()), LoginUserKey, user.LoginTime.AddMinutes(60)); } //添加当前登陆用户Token CacheFactory.GetCacheInstance().WriteCache(user.Token, user.UserId, user.LoginTime.AddMinutes(60)); } catch (Exception ex) { throw new Exception(ex.Message); } }
private string namespaceName = "WIP_Test.TestService";//命名空间 /// <summary> /// 加解密数据 /// </summary> /// <param name="param"></param> /// <returns></returns> public ReturnBody <string> GetEncryptData(GetEncryptData param) { ExceptionInfoEntity exception = WipLogHelper.GetExceptionInfo <GetEncryptData>(namespaceName, "GetEncryptData", param); try { string result = ""; if (param.isEncrypt == "0") {//加密 result = DESEncryptHelper.Encrypt(param.value); } else if (param.isEncrypt == "1") { //解密 result = DESEncryptHelper.Decrypt(param.value); } else { return(BLLHelpler.GetReturnBody <string>(ResCode.FAILURE, ResMsg.FAILURE, "是否解密值错误")); } return(BLLHelpler.GetReturnBody <string>(ResCode.SUCCESS, ResMsg.SUCCESS, result)); } catch (Exception ex) { WipLogHelper.GetExceptionInfoForError(ex, ref exception); return(BLLHelpler.GetReturnBody <string>(ResCode.FAILURE, ResMsg.FAILURE, exception, "出现错误:" + ex.Message)); } }
public LoginInfo Login(string loginName, string password) { LoginInfo loginInfo = null; password = DESEncryptHelper.Encrypt(password); loginName = loginName.Trim(); using (var dbContext = new AccountDbContext()) { var user = dbContext.Users.Include("Roles").Where(u => u.LoginName == loginName && u.Password == password && u.IsActive).FirstOrDefault(); if (user != null) { var ip = FetchHelper.UserIp; loginInfo = dbContext.FindAll <LoginInfo>(p => p.LoginName == loginName && p.ClientIP == ip).FirstOrDefault(); if (loginInfo != null) { loginInfo.LastAccessTime = DateTime.Now; } else { loginInfo = new LoginInfo(user.ID, user.LoginName); loginInfo.ClientIP = ip; loginInfo.BusinessPermissionList = user.BusinessPermissionList; dbContext.Insert <LoginInfo>(loginInfo); } } } return(loginInfo); }
private void picLogin_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.tbUser.Text.Trim()) || string.IsNullOrEmpty(this.tbPsd.Text.Trim())) { this.lbTip.Text = "提示:账号密码不能为空"; return; } bool loginResult = CheckUserDataValid(this.tbUser.Text.Trim(), this.tbPsd.Text.Trim()); if (!loginResult) { this.lbTip.Text = "登录失败,请确认登录用户名密码!"; return; } this.lbTip.Text = "登录成功,请稍后..."; CommonHelper.WriteAppSettings("IsSavePassword", chkMima.Checked.ToString().ToLower()); CommonHelper.WriteAppSettings("LoginAccount", DESEncryptHelper.Encrypt(tbUser.Text)); CommonHelper.WriteAppSettings("LoginPassword", DESEncryptHelper.Encrypt(tbPsd.Text)); this.Animation.Effect = new DSkin.Animations.FadeinFadeoutEffect(); this.Animation.AnimationEnd += Animation_AnimationEnd; this.Animation.Asc = false; this.Animation.Start(); }
private void InsertListTest() { List <UserEntity> list = new List <UserEntity>(); for (int i = 1; i < 5000; i++) { string key = Guid.NewGuid().ToString().Replace("-", ""); string md5 = Md5Helper.Md5("123456"); string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(md5, key)); UserEntity user = new UserEntity { UserId = Guid.NewGuid().ToString().Replace("-", ""), Account = "dashixiong" + i, NickName = "大师兄" + i, Birthday = DateTime.Now.AddDays(-1000), Secretkey = key, Password = realPassword }; user.Create(); list.Add(user); } string time = Stopwatch(() => { UserBll.AddUser(list); }); Console.WriteLine("执行结束,耗时:" + time); }
/// <summary> /// 简化程序(把教师数据分为四张表,分为四个方法进行) Sys_UserLogOn /// </summary> /// <param name="oldDb"></param> /// <param name="newDb"></param> public void ProcessSchoolTeacherSysUserLogON(NanHangAccept oldDb, NHModel newDb) { var newData = newDb.TeacherInfoes.Select(p => new Sys_UserLogOn { F_UserId = p.teacherId }); var oldData = oldDb.Sys_UserLogOn.ToList(); var addList = newData; var Ids = oldData.Select(p => p.F_UserId).ToList(); var InsertList = new List <Sys_UserLogOn>(); foreach (var tea in addList) { if (!Ids.Contains(tea.F_UserId)) { tea.F_Id = tea.F_UserId; tea.F_UserSecretkey = Md5EncryptHelper.Encrypt("0000", 16).ToLower(); tea.F_UserPassword = Md5EncryptHelper.Encrypt(DESEncryptHelper.Encrypt(Md5EncryptHelper.Encrypt("0000", 32).ToLower(), tea.F_UserSecretkey).ToLower(), 32).ToLower(); InsertList.Add(tea); } } //oldDb.BulkInsert(InsertList); oldDb.Sys_UserLogOn.AddRange(InsertList); oldDb.SaveChanges(); }
/// <summary> /// 保存登录信息 /// </summary> /// <param name="m"></param> protected void SetLogin(UserBase m) { _userinfo = m; string keyMsg = DESEncryptHelper.Encrypt("{0}".FormatWith(JsonConvert.SerializeObject(m)), ConfigHelper.AppSettings("LoginDesKey")); //ErrorBLL.Instance.Log("保存登录信息:{0}".FormatWith(keyMsg)); CookieHelper.CreateCookie("uinfo", keyMsg); }
public void RevisePassword(string userPassword, string userId) { var user = Query <User>(p => p.Id.Equals(userId)).FirstOrDefaultAsync().Result; user.Secretkey = Md5EncryptHelper.Encrypt(NumberBuilder.Build_18bit(), 16).ToLower(); user.Password = Md5EncryptHelper.Encrypt(DESEncryptHelper.Encrypt(Md5EncryptHelper.Encrypt(userPassword, 32).ToLower(), user.Secretkey).ToLower(), 32).ToLower(); SaveChanges(); }
private void SetUserLogin(string loginProvider, SysUserModel user) { if (loginProvider == "Cookie") { CookieHelper.SetCookie(SysConstant.SEESIONUSERKEY, DESEncryptHelper.Encrypt(Newtonsoft.Json.JsonConvert.SerializeObject(user)).Replace("+", "%2B")); } else { Session[SysConstant.SEESIONUSERKEY] = user; } }
/// <summary> /// 登录校验 /// </summary> /// <param name="userAccount">用户账号</param> /// <param name="password">密码</param> /// <param name="status">状态</param> /// <returns></returns> public UserEntity CheckLogin(string userAccount, string password, out JsonObjectStatus status) { if (!string.IsNullOrEmpty(userAccount) && !string.IsNullOrEmpty(password)) { //根据用户账号得到用户信息 UserEntity user = o.BllSession.UserBll.FindEntity(u => u.Account.Equals(userAccount)); if (user != null) { if (user.EnabledMark) { string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(password, user.Secretkey)); if (realPassword.Equals(user.Password)) { DateTime lastVisit = DateTime.Now; int logOnCount = (user.LogOnCount).TryToInt32() + 1; if (user.LastVisit != null) { user.PreviousVisit = user.LastVisit.TryToDateTime(); } user.LastVisit = lastVisit; user.LogOnCount = logOnCount; user.UserOnLine = 1; //更新登录信息 int isSucc = o.BllSession.UserBll.Update(user); status = JsonObjectStatus.Success; return(user); } else { status = JsonObjectStatus.PasswordErr; return(user); } } else { status = JsonObjectStatus.AccountNotEnabled; return(user); } } else { status = JsonObjectStatus.UserNotExist; return(null); } } status = JsonObjectStatus.UserNotExist; return(null); }
public ActionResult SaveRevisePassword(string keyValue, string password) { if (keyValue == "System") { throw new Exception("当前账户不能重置密码"); } string key = CommonHelper.GetGuid(); string md5 = Md5Helper.Md5(password); string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(md5, key)); userBLL.RevisePassword(keyValue, realPassword, key); return(Success("密码修改成功,请牢记新密码。")); }
private void btnEncrypt_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtEncryptStr.Text)) { try { MessageBox.Show(DESEncryptHelper.Encrypt(txtEncryptStr.Text)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public void EncryptOrDecrypt() { //arrange string serverCoonection = "Server=39.104.53.29; uid = zaranet; pwd = 123456; database = amusinghoS;"; var miwen = DESEncryptHelper.Encrypt(serverCoonection, "12345678"); string connection = DESEncryptHelper.Decrypt( miwen , "12345678"); //Act var result = DESEncryptHelper.Decrypt("BX+aN6+yUyRBOnwI/LJqs9ASfV9PCSaVeizUy8YKbumoFfQNzLZIhkEMDL5YSrETlyUXAlnJIfFuHGaexoXXUw+71cjSW630", "12345678"); //Assert Assert.Equal(serverCoonection, result); }
public ActionResult ValidationOldPassword(string oldPassword) { string secretkey = OperatorProvider.Provider.Current().Secretkey; string md5 = Md5Helper.Md5(oldPassword); string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(md5, secretkey)); if (realPassword != OperatorProvider.Provider.Current().Password) { return(Error("原密码错误,请重新输入")); } else { return(Success("通过信息验证")); } }
private void InsertTest(int toatl = 10) { Console.WriteLine("\r\n开始测试插入数据...\r\n"); string time = Stopwatch(() => { for (int i = 1; i < toatl; i++) { string time2 = Stopwatch(() => { string key = Guid.NewGuid().ToString().Replace("-", ""); string md5 = Md5Helper.Md5("123456"); string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(md5, key)); UserEntity user = new UserEntity { Account = "System" + i, NickName = "大师兄" + i, Birthday = DateTime.Now.AddDays(-1000), Secretkey = key, Password = realPassword, Gender = 1, SortCode = i //RoleId = CommonHelper.GetGuid() }; user.Create(); ////表名 //string table = EntityAttributeHelper.GetEntityTable<UserEntity>(); ////获取不做映射的字段 //List<string> notMappedField = EntityAttributeHelper.GetNotMappedFields<UserEntity>(); bool res = _userBll.AddUser(user); }); Console.WriteLine("开始测试" + i + ",耗时:" + time2); } }); Console.WriteLine("执行结束,耗时:" + time); }
public ActionResult SaveForm(string keyValue, string strUserEntity, string formInstanceId, string strModuleFormInstanceEntity) { UserEntity userEntity = strUserEntity.JsonToEntity <UserEntity>(); ModuleFormInstanceEntity moduleFormInstanceEntity = strModuleFormInstanceEntity.JsonToEntity <ModuleFormInstanceEntity>(); string key = CommonHelper.GetGuid(); string md5 = Md5Helper.Md5(userEntity.Password); string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(md5, key)); userEntity.Secretkey = key; userEntity.Password = realPassword; string objectId; bool isSucc = userBLL.AddUser(keyValue, userEntity, out objectId); moduleFormInstanceEntity.ObjectId = objectId; moduleFormInstanceBll.SaveEntity(formInstanceId, moduleFormInstanceEntity); return(Success("操作成功。")); }
public void ModifyPwd(User user) { user.Password = DESEncryptHelper.Encrypt(user.Password); using (var dbContext = new AccountDbContext()) { if (dbContext.Users.Any(l => l.ID == user.ID && user.Password == l.Password)) { if (!string.IsNullOrEmpty(user.NewPassword)) { user.Password = DESEncryptHelper.Encrypt(user.NewPassword); } dbContext.Update <User>(user); } else { throw new BusinessException("Password", "原密码不正确!"); } } }
public bool CheckUserDataValid(string userName, string password) { string secretkey = ""; string passWord = ""; using (MAction action = new MAction("Base_User")) { if (action.Fill($"Account='{userName}'")) { secretkey = action.Data["Secretkey"].StringValue; passWord = action.Data["Password"].StringValue; SystemCommon.LoginUser = action.Data.ToEntity <Base_User>(); SystemCommon.LoginUnit = SqlHelper.GetOrganizeById(action.Data["OrganizeId"].StringValue); } else { return(false);//没有此账号 } } string checkPassWord = MD5(password, 32); return(MD5(DESEncryptHelper.Encrypt(checkPassWord.ToLower(), secretkey).ToLower(), 32).ToLower().Equals(passWord)); }
/// <summary> /// 简化程序(把学生数据分为六张表,分为六个方法进行) Sys_UserLogOn /// </summary> /// <param name="oldDb"></param> /// <param name="newDb"></param> public void ProcessSchoolStudentSysUserLogOn(NanHangAccept oldDb, NHModel newDb) { var newData = newDb.StudentInfoes.Select(p => new Sys_UserLogOn { F_UserId = p.studentId }); var oldData = oldDb.Sys_UserLogOn.ToList(); var Ids = oldData.Select(p => p.F_UserId).ToList(); var InsertList = new List <Sys_UserLogOn>(); foreach (var logOn in newData) { if (!Ids.Contains(logOn.F_UserId)) { logOn.F_Id = logOn.F_UserId; logOn.F_UserSecretkey = Md5EncryptHelper.Encrypt("0000", 16).ToLower(); logOn.F_UserPassword = Md5EncryptHelper.Encrypt(DESEncryptHelper.Encrypt(Md5EncryptHelper.Encrypt("0000", 32).ToLower(), logOn.F_UserSecretkey).ToLower(), 32).ToLower(); InsertList.Add(logOn); } } //oldDb.BulkInsert(InsertList); oldDb.Sys_UserLogOn.AddRange(InsertList); oldDb.SaveChanges(); }
public async Task <string> TokenAsync(string phone, string password) { return(await _cache.GetOrCreateAsync(TicksToken + DateTime.Now.ToString("yyyyMMdd") + phone, async entry => { entry.SlidingExpiration = TimeSpan.FromHours(12); var user = await _queries.GetModelAsync(phone); if (user == null) { throw new EPTException($"不存在手机号为为:{phone}的用户"); } else { if (user.Password != password) { throw new EPTException($"密码不正确"); } else { string keyvalue = DESEncryptHelper.Encrypt(phone, DateTime.Now.ToString("yyyyMMdd")); return keyvalue; } } })); }
/// <summary> /// 写入登录信息 /// </summary> /// <param name="user">成员信息</param> public virtual void AddCurrent(OperatorEntity user) { try { if (_loginProvider == "Cookie") { #region 解决cookie时,设置数据权限较多时无法登陆的bug CacheFactory.CacheFactory.GetCacheInstance().WriteCache(user.DataAuthorize, LoginUserKey, user.LoginTime.AddHours(12)); user.DataAuthorize = null; #endregion CookieHelper.WriteCookie(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson())); } else { SessionHelper.AddSession(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson())); } CacheFactory.CacheFactory.GetCacheInstance().WriteCache(user.Token, user.UserId, user.LoginTime.AddHours(12)); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// 登录校验 /// </summary> /// <param name="userAccount">用户账号</param> /// <param name="password">密码</param> /// <returns></returns> public Tuple <UserEntity, JsonObjectStatus> CheckLogin(string userAccount, string password) { Tuple <UserEntity, JsonObjectStatus> res = new Tuple <UserEntity, JsonObjectStatus>(null, JsonObjectStatus.UserNotExist); IDbTransaction tran = null; Logger(this.GetType(), "CheckLogin-登录校验", () => { using (var conn = this.BaseRepository().GetBaseConnection()) { tran = conn.BeginTransaction(); if (!string.IsNullOrEmpty(userAccount) && !string.IsNullOrEmpty(password)) { //根据用户账号得到用户信息 //UserEntity user = this.BaseRepository().FindEntity<UserEntity>(u => u.Account.Equals(userAccount)); UserEntity user = this.BaseRepository().FindEntity <UserEntity>(conn, u => u.Account == userAccount, tran); if (user != null) { if (user.EnabledMark) { string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(password, user.Secretkey)); if (realPassword.Equals(user.Password)) { DateTime lastVisit = DateTime.Now; int logOnCount = (user.LogOnCount).TryToInt32() + 1; if (user.LastVisit != null) { user.PreviousVisit = user.LastVisit.TryToDateTime(); } user.LastVisit = lastVisit; user.LogOnCount = logOnCount; user.UserOnLine = 1; //更新登录信息 //int isSucc = this.BaseRepository().Update<UserEntity>(new UserEntity { Id = user.Id, LastVisit = lastVisit, LogOnCount = logOnCount, UserOnLine = 1 }, e => e.Id == user.Id); UserEntity update = new UserEntity { Id = user.Id, LastVisit = lastVisit, LogOnCount = logOnCount, UserOnLine = 1, EnabledMark = user.EnabledMark, DeleteMark = user.DeleteMark }; int isSucc = this.BaseRepository().Update <UserEntity>(conn, update, tran); res = new Tuple <UserEntity, JsonObjectStatus>(user, JsonObjectStatus.Success); } else { res = new Tuple <UserEntity, JsonObjectStatus>(null, JsonObjectStatus.PasswordErr); } } else { res = new Tuple <UserEntity, JsonObjectStatus>(null, JsonObjectStatus.AccountNotEnabled); } } else { res = new Tuple <UserEntity, JsonObjectStatus>(null, JsonObjectStatus.UserNotExist); } } tran.Commit(); } }, e => { Trace.WriteLine(e.Message); }); return(res); }
/// <summary> /// 保存用户表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="userEntity">用户实体</param> /// <param name="objectId">用户ID</param> /// <returns></returns> public bool AddUser(string keyValue, UserEntity userEntity, out string objectId) { bool isSucc = false; IDbTransaction tran = null; Logger(this.GetType(), "AddUser-保存用户表单(新增、修改)", () => { using (var conn = this.BaseRepository().GetBaseConnection()) { tran = conn.BeginTransaction(); if (!string.IsNullOrEmpty(keyValue)) { //更新操作 userEntity.Modify(keyValue); userEntity.EnabledMark = true; userEntity.DeleteMark = false; int res = this.BaseRepository().Update <UserEntity>(conn, userEntity, tran); isSucc = res > 0; } else { //新增操作 userEntity.Create(); string key = CommonHelper.GetGuid(); string md5 = Md5Helper.Md5(userEntity.Password); string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(md5, key)); userEntity.Password = realPassword; userEntity.Secretkey = key; int res = this.BaseRepository().Insert <UserEntity>(conn, userEntity, tran); isSucc = res > 0; } #region 添加角色、岗位、职位信息 //删除历史用户角色关系 this.BaseRepository().Delete <UserRelationEntity>(conn, u => u.IsDefault == true && u.Id == userEntity.Id, tran); //用户关系 List <UserRelationEntity> userRelation = new List <UserRelationEntity>(); //角色 if (!string.IsNullOrEmpty(userEntity.RoleId)) { userRelation.Add(new UserRelationEntity { Category = 2, Id = CommonHelper.GetGuid(), UserId = userEntity.Id, ObjectId = userEntity.RoleId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = true }); } //岗位 if (!string.IsNullOrEmpty(userEntity.DutyId)) { userRelation.Add(new UserRelationEntity { Category = 3, Id = CommonHelper.GetGuid(), UserId = userEntity.Id, ObjectId = userEntity.DutyId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = true }); } //职位 if (!string.IsNullOrEmpty(userEntity.PostId)) { userRelation.Add(new UserRelationEntity { Category = 4, Id = CommonHelper.GetGuid(), UserId = userEntity.Id, ObjectId = userEntity.PostId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = true }); } //保持用户角色关系 if (userRelation.Count > 0) { int res1 = this.BaseRepository().Insert <UserRelationEntity>(conn, userRelation, tran); } #endregion 添加角色、岗位、职位信息 tran.Commit(); } }, e => { Trace.WriteLine(e.Message); }); objectId = userEntity.Id; return(isSucc); }
/// <summary> /// 登录校验 /// </summary> /// <param name="userAccount">用户账号</param> /// <param name="password">密码</param> /// <param name="status">状态</param> /// <returns></returns> public UserEntity CheckLogin(string userAccount, string password, out JsonObjectStatus status) { if (!string.IsNullOrEmpty(userAccount) && !string.IsNullOrEmpty(password)) { //根据用户账号得到用户信息 //UserEntity user = this.BaseRepository().FindEntity<UserEntity>(u => u.Account.Equals(userAccount)); UserEntity user = this.BaseRepository().FindEntity <UserEntity>(u => u.Account == userAccount); if (user != null) { if (user.EnabledMark) { string realPassword = Md5Helper.Md5(DESEncryptHelper.Encrypt(password, user.Secretkey)); if (realPassword.Equals(user.Password)) { DateTime lastVisit = DateTime.Now; int logOnCount = (user.LogOnCount).TryToInt32() + 1; if (user.LastVisit != null) { user.PreviousVisit = user.LastVisit.TryToDateTime(); } user.LastVisit = lastVisit; user.LogOnCount = logOnCount; user.UserOnLine = 1; //更新登录信息 //int isSucc = this.BaseRepository().Update<UserEntity>(new UserEntity { Id = user.Id, LastVisit = lastVisit, LogOnCount = logOnCount, UserOnLine = 1 }, e => e.Id == user.Id); UserEntity update = new UserEntity { Id = user.Id, LastVisit = lastVisit, LogOnCount = logOnCount, UserOnLine = 1, EnabledMark = user.EnabledMark, DeleteMark = user.DeleteMark }; int isSucc = this.BaseRepository().Update <UserEntity>(update); status = JsonObjectStatus.Success; return(user); } else { status = JsonObjectStatus.PasswordErr; return(user); } } else { status = JsonObjectStatus.AccountNotEnabled; return(user); } } else { status = JsonObjectStatus.UserNotExist; return(null); } } status = JsonObjectStatus.UserNotExist; return(null); }
public ActionResult CheckLogin(string username, string password, string verifycode, int autologin) { ActionResult res = null; LogEntity logEntity = new LogEntity { CategoryId = (int)CategoryType.Login, OperateTypeId = ((int)OperationType.Login).ToString(), OperateType = OperationType.Login.GetEnumDescription(), OperateAccount = username, OperateUserId = username, OperateTime = DateTime.Now, IPAddress = NetHelper.Ip, IPAddressName = "",//NetHelper.GetAddressByIP(NetHelper.Ip), Browser = NetHelper.Browser, Module = ConfigHelper.GetValue("SoftName") }; Logger(this.GetType(), "登录验证-CheckLogin", () => { #region 验证码验证 string code = Md5Helper.Md5(verifycode.ToLower()); string sessionCode = SessionHelper.GetSession <string>("session_verifycode"); if (string.IsNullOrEmpty(sessionCode) || code != sessionCode) { res = Error("验证码错误,请重新输入"); } #endregion #region 账户验证 else { Tuple <UserEntity, JsonObjectStatus> tuple = userBll.CheckLogin(username, password); JsonObjectStatus status = tuple.Item2; UserEntity user = tuple.Item1; if (status != JsonObjectStatus.Success || user == null) { res = Error(status.GetEnumDescription()); } else { string objId = permissionBll.GetObjectString(user.Id); OperatorEntity operators = new OperatorEntity { UserId = user.Id, Code = user.EnCode, Account = user.Account, UserName = user.RealName ?? user.NickName, Password = user.Password, Secretkey = user.Secretkey, CompanyId = user.OrganizeId, DepartmentId = user.DepartmentId, IPAddress = NetHelper.Ip, IPAddressName = "",//NetHelper.GetAddressByIP(NetHelper.Ip), ObjectId = objId, LoginTime = DateTime.Now, Token = DESEncryptHelper.Encrypt(CommonHelper.GetGuid(), user.Secretkey) }; //写入当前用户数据权限 string ReadAutorize = authorizeBLL.GetDataAuthor(operators); string ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators); string WriteAutorize = authorizeBLL.GetDataAuthor(operators, true); string WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true); AuthorizeDataModel dataAuthorize = new AuthorizeDataModel { ReadAutorize = ReadAutorize, ReadAutorizeUserId = ReadAutorizeUserId, WriteAutorize = WriteAutorize, WriteAutorizeUserId = WriteAutorizeUserId }; operators.DataAuthorize = dataAuthorize; //判断是否系统管理员 operators.IsSystem = user.Account == "System"; //写入登录信息 OperatorProvider.Provider.AddCurrent(operators); //写入日志 logEntity.ExecuteResult = 1; logEntity.ExecuteResultJson = "登录成功"; logBll.WriteLog(logEntity); res = Success("登录成功", user, "/Home/AdminDefault"); } } #endregion }, e => { CookieHelper.DelCookie("__autologin");//清除自动登录 logEntity.ExecuteResult = -1; logEntity.ExecuteResultJson = e.Message; logBll.WriteLog(logEntity); res = Error("系统异常:" + e.Message); }, () => { SessionHelper.RemoveSession("session_verifycode"); }); return(res); }
public ActionResult CheckLogin(string username, string password, string verifycode, int autologin) { ActionResult res = null; Logger(this.GetType(), "登录验证-CheckLogin", () => { #region 验证码验证 string code = Md5Helper.Md5(verifycode.ToLower()); string sessionCode = SessionHelper.GetSession <string>("session_verifycode"); if (string.IsNullOrEmpty(sessionCode) || code != sessionCode) { res = Error("验证码错误,请重新输入"); } #endregion #region 账户验证 else { JsonObjectStatus status; UserEntity user = _userBll.CheckLogin(username, password, out status); if (status != JsonObjectStatus.Success || user == null) { res = Error(status.GetEnumDescription()); } else { string objId = _permissionBll.GetObjectString(user.UserId); OperatorEntity operators = new OperatorEntity { UserId = user.UserId, Code = user.EnCode, Account = user.Account, UserName = user.RealName ?? user.NickName, Password = user.Password, Secretkey = user.Secretkey, CompanyId = user.OrganizeId, DepartmentId = user.DepartmentId, IPAddress = NetHelper.Ip, IPAddressName = NetHelper.GetAddressByIP(NetHelper.Ip), ObjectId = objId, LoginTime = DateTime.Now, Token = DESEncryptHelper.Encrypt(CommonHelper.GetGuid(), user.Secretkey) }; //写入当前用户数据权限 AuthorizeDataModel dataAuthorize = new AuthorizeDataModel { ReadAutorize = _authorizeBll.GetDataAuthor(operators), ReadAutorizeUserId = _authorizeBll.GetDataAuthorUserId(operators), WriteAutorize = _authorizeBll.GetDataAuthor(operators, true), WriteAutorizeUserId = _authorizeBll.GetDataAuthorUserId(operators, true) }; operators.DataAuthorize = dataAuthorize; //判断是否系统管理员 operators.IsSystem = user.Account == "System"; //写入登录信息 OperatorProvider.Provider.AddCurrent(operators); res = Success("登录成功", user, "/Home/AdminDefault"); } } #endregion }, e => { res = Error("系统异常:" + e.Message); }, () => { SessionHelper.RemoveSession("session_verifycode"); }); return(res); }