Class OneTimePassword
- Namespace
- PolarStudio
- Assembly
- PolarStudio.dll
This Class is a helper to manage one time passwords using the TOTP mechanism.
public class OneTimePassword
- Inheritance
-
OneTimePassword
- Inherited Members
- Extension Methods
Constructors
OneTimePassword(string)
Constructor for a new one time password. If no key is specified, a new random key is created.
public OneTimePassword(string pKey = "")
Parameters
pKey
string
Properties
Key
This property gets/sets the key for this one time password helper object. If the key is an even length hex string, the raw key is expected to be the bytes represented by that hex string. Else, the raw key is expected to be the text value of the given key.
public string Key { get; set; }
Property Value
Key_Raw
Returns the key as a binary string.
public string Key_Raw { get; }
Property Value
Methods
CheckPassword(string, bool)
This method checks the given password. By default it will check 1 box in the past and 1 in the future (and the current).
public bool CheckPassword(string pPassword, bool pExtraTimeRange = false)
Parameters
pPassword
stringThe one time password to check.
pExtraTimeRange
boolIf this parameter is set to true, the check will add 1 box in the past and future.
Returns
GenerateNewKey()
This method can be used to create a new random key.
public void GenerateNewKey()
GetOneTimePassword(int)
This method returns the value of a one time password. The offset can be used to get a value in the past (-x) or in the future (+x). Using 30 seconds time boxes.
public string GetOneTimePassword(int pOffSet = 0)
Parameters
pOffSet
int
Returns
GetQRcode(string, int)
The method returns a the binary data for a PNG image with a QR code to init using the given key
public string GetQRcode(string pIdentity, int pBlockWidthFactor = 0)
Parameters
pIdentity
stringThe name of the application as to be shown in the authenticator app.
pBlockWidthFactor
intThis parameter sets the size of one block in the QR code. Larger numbers will give larger images.
Returns
- string
A binary representing the PNG image.
OTPauthUrl(string)
This method returns an URL that can be used to add a key with a given name to an authenticator app. This url can for example be embedded in a QR code.
public string OTPauthUrl(string pIdentity)
Parameters
pIdentity
stringThe name of the application as to be shown in the authenticator app.
Returns
- string
An URL using the otpauth-scheme.