Class Code
Represents a One-Time Password (OTP) code generated on Yubikey using OATH application.
public class Code
- Inheritance
-
objectCode
Remarks
The YubiKey supports Open Authentication (OATH) standards for generating OTP codes. The OTPs need to be calculated because the YubiKey doesn't have an internal clock. The system time is used and passed to the YubiKey.
Constructors
Code()
Constructs an instance of Code class.
public Code()
Code(string?, CredentialPeriod)
Constructs an instance of the Code class.
public Code(string? value, CredentialPeriod period)
Parameters
value
stringThe generated OTP code.
period
CredentialPeriodThe credential period to calculate the OTP code validity.
Remarks
The credential period is used to set a validity for OTP code. The validity for HOTP code is set to DateTimeOffset.MaxValue because HOTP code is not time-based. The validity for TOTP code is set to DateTimeOffset.Now + credential period (15, 30, or 60 seconds). Also, it is "rounded" to the nearest 15, 30, or 60 seconds. For example, it will start at 1:14:30 and not 1:14:34 if the timestep is 30 seconds.
Exceptions
- ArgumentException
The provided period is invalid.
Properties
ValidFrom
The timestamp that was used to generate the OTP code.
public DateTimeOffset? ValidFrom { get; set; }
Property Value
- DateTimeOffset?
ValidUntil
The timestamp when the OTP code becomes invalid.
public DateTimeOffset? ValidUntil { get; set; }
Property Value
- DateTimeOffset?
Value
The generated OTP code.
public string? Value { get; set; }
Property Value
- string
Methods
IsValid()
Checks if the OTP code is still valid.
public bool IsValid()
Returns
- bool