Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public interface RecoveryCodeRepository

Known subtypesInMemoryRecoveryCodeRepository, JdbcRecoveryCodeRepository

Where recovery codes are kept: as hashes, never as the codes.

Methods

public abstract void replace(String username, List<String> codeHashes)Replaces every code of username with these hashes.
public abstract List<String> findHashes(String username)A snapshot of the user’s salted password hashes, for checking a presented code.
public abstract boolean consume(String username, String codeHash)Uses one code up.
public abstract int count(String username)How many codes username has left.

Method details

replace

public abstract void replace(String username, List<String> codeHashes)
Replaces every code of username with these hashes.

findHashes

public abstract List<String> findHashes(String username)
A snapshot of the user’s salted password hashes, for checking a presented code. An unknown user has an empty list. Consumption still goes through consume.

consume

public abstract boolean consume(String username, String codeHash)

Uses one code up.

The test and the removal are one step: a code is good once, however many requests present it at the same moment.

Returns

whether this call removed it

count

public abstract int count(String username)
How many codes username has left.