Interface OneTimeCodeRepository
- All Known Implementing Classes:
JdbcOneTimeCodeRepository
public interface OneTimeCodeRepository
Port that stores the numeric one-time codes. An implementation never returns
null.-
Method Summary
Modifier and TypeMethodDescriptionbooleanSpends a code, in one atomic step, so that two concurrent requests cannot both use it.intdeleteExpired(Instant now) Deletes every code that has expired.findActive(String bindingId, String username, Instant now) Finds the code that is still active for a binding and a user.intCounts a wrong submission, in one atomic step.voidsave(OneTimeCode code) Stores a code, replacing any other active code of the same binding and user name so that only the latest one can be used.
-
Method Details
-
save
Stores a code, replacing any other active code of the same binding and user name so that only the latest one can be used.- Parameters:
code- the code to store.
-
findActive
Finds the code that is still active for a binding and a user.- Parameters:
bindingId- identifier binding the code to the requesting browser session.username- user name of the account.now- current instant; an expired code is not active.- Returns:
- the active code, or empty when there is none.
-
incrementAttempts
Counts a wrong submission, in one atomic step.- Parameters:
id- identifier of the code.- Returns:
- the number of attempts after the increment, or
0when the code no longer exists.
-
consume
Spends a code, in one atomic step, so that two concurrent requests cannot both use it.- Parameters:
id- identifier of the code.- Returns:
truewhen the code existed and is now spent.
-
deleteExpired
Deletes every code that has expired.- Parameters:
now- current instant.- Returns:
- the number of deleted codes.
-