Search in sources :

Example 1 with InvalidVerificationCodeException

use of org.molgenis.security.twofactor.exceptions.InvalidVerificationCodeException in project molgenis by molgenis.

the class TwoFactorAuthenticationServiceImpl method isVerificationCodeValidForUser.

@Override
public boolean isVerificationCodeValidForUser(String verificationCode) {
    boolean isValid = false;
    UserSecret userSecret = getSecret();
    if (!userIsBlocked()) {
        try {
            if (otpService.tryVerificationCode(verificationCode, userSecret.getSecret())) {
                isValid = true;
                updateFailedLoginAttempts(0);
            }
        } catch (InvalidVerificationCodeException err) {
            updateFailedLoginAttempts(userSecret.getFailedLoginAttempts() + FAILED_LOGIN_ATTEMPT_ITERATION);
            if (!userIsBlocked()) {
                throw err;
            }
        }
    }
    return isValid;
}
Also used : UserSecret(org.molgenis.security.twofactor.model.UserSecret) InvalidVerificationCodeException(org.molgenis.security.twofactor.exceptions.InvalidVerificationCodeException)

Aggregations

InvalidVerificationCodeException (org.molgenis.security.twofactor.exceptions.InvalidVerificationCodeException)1 UserSecret (org.molgenis.security.twofactor.model.UserSecret)1