Class TwoFactorService
java.lang.Object
springboot.bg.harisauto.twofactor.TwoFactorService
TwoFactorService.java - Issues and verifies the one-time codes used at sign-in.
- Author:
- Kristian Popov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumOutcome of checking a submitted code. -
Constructor Summary
ConstructorsConstructorDescriptionTwoFactorService(TwoFactorTokenRepository repository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, EmailService emailService, TwoFactorProperties properties) Constructor. -
Method Summary
-
Constructor Details
-
TwoFactorService
public TwoFactorService(TwoFactorTokenRepository repository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, EmailService emailService, TwoFactorProperties properties) Constructor.
-
-
Method Details
-
issueCode
Issues a fresh code for a user and emails it.Any earlier code is deleted first, so only the most recent one can ever be used.
- Parameters:
user- The user signing in.
-
verify
Checks a submitted code.A wrong code counts against the attempt limit; reaching the limit discards the code entirely, so guessing forces the user to start sign-in again rather than continue against the same secret.
- Parameters:
userId- The user being verified.submittedCode- The code entered.- Returns:
- The outcome of the check.
-