public ChangePasswordState ChangePassword(ChangePassword password) { if (!ValidateHelper.CheckPassword(password.NewPassword)) { return(ChangePasswordState.InvalidNewPassword); } var user = _userDal.Get(password.Id); if (user == null) { return(ChangePasswordState.InvalidOpt); } if (!PasswordEncrypt.CheckPassword(password.OldPassword, user.Salt, user.Password)) { return(ChangePasswordState.InvalidOldPassword); } if (!_userDal.UpdatePassword(password.Id, PasswordEncrypt.GetEncryptPassword(password.NewPassword, user.Salt))) { return(ChangePasswordState.Failed); } return(ChangePasswordState.Successed); }
public LoginState Login(User user) { if (!string.IsNullOrEmpty(user.Account)) { user.Account = user.Account.ToLower(); } var userInfo = _userDal.Get(user.Account); if (userInfo == null) { return(LoginState.InvalidAccountOrPassword); } if (user.Id == int.MinValue) { if (!user.Password.Equals(userInfo.Password)) { return(LoginState.InvalidAccountOrPassword); } } else { if (!PasswordEncrypt.CheckPassword(user.Password, userInfo.Salt, userInfo.Password)) { return(LoginState.InvalidAccountOrPassword); } } if (!userInfo.IsAudit || userInfo.ExpireDate == null) { user.Id = userInfo.Id; return(LoginState.NotAudit); } if (DateTime.UtcNow > userInfo.ExpireDate.Value) { return(LoginState.Expired); } if (userInfo.Lock) { return(LoginState.Locked); } user.Id = userInfo.Id; return(LoginState.Successed); }