@Test void testTryVerificationKeyFailed() { assertThrows( InvalidVerificationCodeException.class, () -> otpServiceImpl.tryVerificationCode("", "secretKey")); }
@Override public boolean tryVerificationCode(String verificationCode, String secretKey) { boolean isValid; if (StringUtils.hasText(secretKey)) { if (verificationCode == null) { throw new InvalidVerificationCodeException("Verificationcode is mandatory"); } else { final Totp totp = new Totp(secretKey); if (isValidLong(verificationCode) && totp.verify(verificationCode)) { isValid = true; } else { throw new InvalidVerificationCodeException("Invalid verification code entered"); } } } else { throw new InvalidVerificationCodeException( "Two factor authentication secret key is not available"); } return isValid; }
OtpServiceImpl implements OtpService { @Override public boolean tryVerificationCode(String verificationCode, String secretKey) { boolean isValid; if (StringUtils.hasText(secretKey)) { if (verificationCode == null) { throw new InvalidVerificationCodeException("Verificationcode is mandatory"); } else { final Totp totp = new Totp(secretKey); if (isValidLong(verificationCode) && totp.verify(verificationCode)) { isValid = true; } else { throw new InvalidVerificationCodeException("Invalid verification code entered"); } } } else { throw new InvalidVerificationCodeException( "Two factor authentication secret key is not available"); } return isValid; } }
OtpServiceImpl implements OtpService { @Override public boolean tryVerificationCode(String verificationCode, String secretKey) { boolean isValid; if (StringUtils.hasText(secretKey)) { if (verificationCode == null) { throw new InvalidVerificationCodeException("Verificationcode is mandatory"); } else { final Totp totp = new Totp(secretKey); if (isValidLong(verificationCode) && totp.verify(verificationCode)) { isValid = true; } else { throw new InvalidVerificationCodeException("Invalid verification code entered"); } } } else { throw new InvalidVerificationCodeException( "Two factor authentication secret key is not available"); } return isValid; } OtpServiceImpl(AppSettings appSettings); }
OtpServiceImpl implements OtpService { @Override public boolean tryVerificationCode(String verificationCode, String secretKey) { boolean isValid; if (StringUtils.hasText(secretKey)) { if (verificationCode == null) { throw new InvalidVerificationCodeException("Verificationcode is mandatory"); } else { final Totp totp = new Totp(secretKey); if (isValidLong(verificationCode) && totp.verify(verificationCode)) { isValid = true; } else { throw new InvalidVerificationCodeException("Invalid verification code entered"); } } } else { throw new InvalidVerificationCodeException( "Two factor authentication secret key is not available"); } return isValid; } OtpServiceImpl(AppSettings appSettings); @Override boolean tryVerificationCode(String verificationCode, String secretKey); @Override String getAuthenticatorURI(String secretKey); }
OtpServiceImpl implements OtpService { @Override public boolean tryVerificationCode(String verificationCode, String secretKey) { boolean isValid; if (StringUtils.hasText(secretKey)) { if (verificationCode == null) { throw new InvalidVerificationCodeException("Verificationcode is mandatory"); } else { final Totp totp = new Totp(secretKey); if (isValidLong(verificationCode) && totp.verify(verificationCode)) { isValid = true; } else { throw new InvalidVerificationCodeException("Invalid verification code entered"); } } } else { throw new InvalidVerificationCodeException( "Two factor authentication secret key is not available"); } return isValid; } OtpServiceImpl(AppSettings appSettings); @Override boolean tryVerificationCode(String verificationCode, String secretKey); @Override String getAuthenticatorURI(String secretKey);  }