public Task <bool> CreateAsync(UserDto dto) { return(Task <bool> .Factory.StartNew(() => { try { User user = _mapper.Map <User>(dto); _logger.LogDebug(JsonConvert.SerializeObject(user)); var pwmd5 = MD5Tools.MD5Encrypt32(dto.Password); var scmd5 = Guid.NewGuid().ToString("N"); var pwdHash = MD5Tools.MD5Encrypt64(pwmd5 + scmd5); user.PasswordHash = pwdHash; user.SecurityCode = scmd5; _userRepository.Add(user); int count = _unitOfWork.SaveChanges(); _logger.LogDebug("保存成功" + count); } catch (System.Exception ex) { _logger.LogError(ex.Message); return false; } return true; })); }
public Task <ClaimsIdentity> LoginAsync(LoginDto dto) { User user = _userRepository.Query.FirstOrDefault(f => f.Email == dto.Account || f.Phone == dto.Account || f.UserName == dto.Account); if (user == null) { return(Task.FromResult <ClaimsIdentity>(null)); } string pwmd5 = MD5Tools.MD5Encrypt32(dto.Password); string pwdHash = MD5Tools.MD5Encrypt64(pwmd5 + user.SecurityCode); if (pwdHash == user.PasswordHash) { return(Task.FromResult(new ClaimsIdentity(new System.Security.Principal.GenericIdentity(dto.Account, "Token"), new Claim[] { }))); } return(Task.FromResult <ClaimsIdentity>(null)); }