GoogleAuthenticator

class GoogleAuthenticator(base32secret: ByteArray)

This class is a decorator of the TimeBasedOneTimePasswordGenerator that provides the default values used by the Google Authenticator:

  • HMAC algorithm: SHA1;

  • time step: 30 seconds;

  • and code digits: 6.

Parameters

base32secret

the shared Base32-encoded-encoded secret.

Constructors

Link copied to clipboard
fun GoogleAuthenticator(base32secret: String)
Link copied to clipboard
fun GoogleAuthenticator(base32secret: ByteArray)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun generate(timestamp: Date = Date(System.currentTimeMillis())): String

Generates a code as a TOTP one-time password.

Link copied to clipboard
fun isValid(code: String, timestamp: Date = Date(System.currentTimeMillis())): Boolean

Validates the given code.

Link copied to clipboard
fun otpAuthUriBuilder(): OtpAuthUriBuilder.Totp

Creates an OtpAuthUriBuilder, which pre-configured with the secret, as well as the fixed Google authenticator configuration for the algorithm, code digits and time step.