/// <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(); }
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); }
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 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(); }
/// <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(); }