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

package com.codename1.backend.security.mfa

A second factor at sign-in: one-time codes from an authenticator app, and the recovery codes that stand in for a lost phone.

http.mfa(...) turns it on for a chain. A user who has enrolled – see TotpService – is not signed in by their password alone: the request stays anonymous, and they are sent to a page that asks for the code.

The secret an authenticator app shares with the server is kept by a TotpRepository, in memory or sealed in the server’s database; recovery codes are kept as hashes by a RecoveryCodeRepository.

Types

class EmailCodeWhat an EmailCodeRepository holds for one user.
interface EmailCodeRepositoryWhere EmailCodeService keeps who signs in with a mailed code, and the hash of the code each is waiting to enter.
class EmailCodeServiceA code mailed to the user as the second step of signing in.
class InMemoryEmailCodeRepositoryMailed codes kept in this process: gone when it stops.
class InMemoryRecoveryCodeRepositoryRecovery codes kept in this process: gone when it stops.
class InMemoryTotpRepositorySecrets kept in this process: gone when it stops.
class JdbcEmailCodeRepositoryMailed codes kept in the server’s database, in the cn1_mfa_email table of SecuritySchema.
class JdbcRecoveryCodeRepositoryRecovery codes kept in the server’s database, in the cn1_mfa_recovery_code table of SecuritySchema.
class JdbcTotpRepositorySecrets kept in the server’s database, in the cn1_mfa_totp table of SecuritySchema.
interface RecoveryCodeRepositoryWhere recovery codes are kept: as hashes, never as the codes.
class RecoveryCodeServiceRecovery codes: what signs a user in when their authenticator app is gone.
class TotpCredentialWhat the server keeps of one user’s authenticator app.
class TotpEnrollmentWhat a user needs to add the server to their authenticator app: shown once, when enrolment begins.
interface TotpRepositoryWhere the secrets of users’ authenticator apps are kept.
class TotpServiceTime-based one-time codes (RFC 6238): enrolling a user’s authenticator app, and checking the codes it shows.