Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public interface TotpRepository
Known subtypesInMemoryTotpRepository, JdbcTotpRepository
Where the secrets of users’ authenticator apps are kept. A user has one;
names are compared without regard to the case of A to Z.
TotpService uses the secret-bound overloads of confirm and advance.
Custom stores must implement their atomic comparison and update; the defaults
refuse the operation rather than fall back to an unbound update.
Methods
public abstract void save(String username, byte[] secret) | Stores a new, unconfirmed secret for username, replacing any other. |
public abstract TotpCredential find(String username) | The credential of username, or null. |
public abstract boolean confirm(String username) | Marks the credential confirmed, if it is there and was not. |
public abstract boolean advance(String username, long step) | Records that a code of time step step was accepted, if no code of that step or a later one has been. |
public default boolean confirm(String username, byte[] expectedSecret, long step) | Confirms and consumes a code only if the current, unconfirmed credential still has the secret that was verified. |
public default boolean advance(String username, byte[] expectedSecret, long step) | Consumes a sign-in code only if the confirmed credential still has the verified secret and its last accepted step is lower. |
public abstract boolean delete(String username) | Forgets the credential. |
Method details
save
public abstract void save(String username, byte[] secret)username, replacing any other.find
public abstract TotpCredential find(String username)username, or null.confirm
public abstract boolean confirm(String username)Returns
advance
public abstract boolean advance(String username, long step)Records that a code of time step step was accepted, if no code of
that step or a later one has been.
The test and the change are one step, which is what makes a code good once: of two requests presenting the same code at the same moment, on one server or two, exactly one is told true.
Returns
confirm
public default boolean confirm(String username, byte[] expectedSecret, long step)advance
public default boolean advance(String username, byte[] expectedSecret, long step)delete
public abstract boolean delete(String username)