/// <summary> /// 创建用户 /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <bool> CreateUser(UserDto user) { if (user == null) { return(false); } var entity = Mapper.Map <UserEntity>(user); var passwordSalt = GeneratePasswordSalt(); entity.Password = SecureHelper.MD5AddingSalt(user.Password, passwordSalt); entity.PasswordSalt = passwordSalt; entity.Status = (int)UserStatus.Normal; return(await userRepository.AddUser(entity)); }
/// <summary> /// CheckUserNameAndPwd /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public async Task <UserModel> IsValidUserCredentials(string userName, string password) { if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password)) { throw new HXException(HXExceptionCode.AUTH_FAILED, "用户名或者密码为空", HXExceptionLevel.Warning); } var user = await userRepository.GetUser(userName); if (user == null) { throw new HXException(HXExceptionCode.USER_NOT_EXISTS, "用户不存在", HXExceptionLevel.Warning); } string encryptedPassword = SecureHelper.MD5(password); //一次MD5加密 string encryptedWithSaltPassword = SecureHelper.MD5AddingSalt(password, user.PasswordSalt); //加盐MD5 if (encryptedWithSaltPassword.ToLower() != user.Password.ToLower()) { throw new HXException(HXExceptionCode.AUTH_FAILED, "密码错误", HXExceptionLevel.Warning); } return(Mapper.Map <UserModel>(user)); }