Class JdbcEmailCodeRepository
java.lang.Object
com.codename1.backend.security.mfa.JdbcEmailCodeRepository
- All Implemented Interfaces:
EmailCodeRepository
Mailed codes kept in the server's database, in the
cn1_mfa_email table
of SecuritySchema. An attempt is counted, and a code used up, by one
UPDATE whose condition is the limit or the code itself, so servers
sharing the table cannot between them allow one attempt too many or take
one code twice.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanUses the waiting code up, if it is still the one withcodeHash.booleancountAttempt(String username, int max) Counts one attempt against the waiting code.What is held forusername, or null.booleanKeeps a new code forusernamein place of the one waiting, when the user signs in with a mailed code and the last was sent at or beforesentBefore-- or aftersentAt, which is a clock that was set back.voidsetEnabled(String username, boolean enabled) Turns the mailed code on or off forusername.
-
Constructor Details
-
JdbcEmailCodeRepository
-
-
Method Details
-
find
Description copied from interface:EmailCodeRepositoryWhat is held forusername, or null.- Specified by:
findin interfaceEmailCodeRepository
-
setEnabled
Description copied from interface:EmailCodeRepositoryTurns the mailed code on or off forusername. Turning it off drops any code that is waiting.- Specified by:
setEnabledin interfaceEmailCodeRepository
-
saveCode
public boolean saveCode(String username, String codeHash, long expiresAt, long sentAt, long sentBefore, int max) Description copied from interface:EmailCodeRepositoryKeeps a new code for
usernamein place of the one waiting, when the user signs in with a mailed code and the last was sent at or beforesentBefore-- or aftersentAt, which is a clock that was set back. Of several callers at once one is answered true, so one mail leaves.The attempts counted against the code it replaces are counted against this one too, unless that code had run out or been used: asking for another is not a way to more tries. And a code with
maxattempts counted is not replaced before it runs out, so the wait that follows them ends at a moment that asking again does not move.- Specified by:
saveCodein interfaceEmailCodeRepository
-
countAttempt
Description copied from interface:EmailCodeRepositoryCounts one attempt against the waiting code. False whenmaxhave been counted already; of several callers at once, no more thanmaxare answered true.- Specified by:
countAttemptin interfaceEmailCodeRepository
-
clear
Description copied from interface:EmailCodeRepositoryUses the waiting code up, if it is still the one withcodeHash. Of two callers with the same code, one is answered true.signedInsays the code was typed in and accepted, which also forgets when it was sent: the next sign-in is then mailed a code at once. A code cleared because its mail failed keeps the time, so a failing send is still spaced out.- Specified by:
clearin interfaceEmailCodeRepository
-