/// <summary> /// Create a new secret for a user /// </summary> /// <param name="systemSettings">System settings</param> /// <returns>New user settings</returns> public static MobileAppUserSettings CreateNewSecret(MobileAppSystemSettings systemSettings) { return(new MobileAppUserSettings() { Secret = Internal.TotpHelper.CreateNewSecret(systemSettings.SecretLengthInBits) }); }
/// <summary> /// Check if a code is valid /// </summary> /// <param name="systemSettings">System settings</param> /// <param name="userSettings">User settings</param> /// <param name="code">Code to check</param> /// <returns>True if the code is valid, false if not</returns> public static bool Authenticate(MobileAppSystemSettings systemSettings, MobileAppUserSettings userSettings, int code) { int timestamp = Internal.TotpHelper.TimeStamp; bool valid = Internal.TotpHelper.Authenticate(userSettings.Secret, systemSettings.TimeWindowSize, timestamp, code); return(valid && _invalidCodes.CheckAndAdd(code, timestamp, systemSettings.TimeWindowSize)); }
/// <summary> /// Get the Url to be encoded in a QR code and scanned into the app /// </summary> /// <param name="systemSettings">System settings</param> /// <param name="userSettings">User settings</param> /// <param name="label">Label to show in the app</param> /// <returns>The Url</returns> public static string GetSecretUrl(MobileAppSystemSettings systemSettings, MobileAppUserSettings userSettings, string label) { return(Internal.TotpHelper.GetSecretUrl(userSettings.Secret, label)); }
/// <summary> /// Get the Url to be encoded in a QR code and scanned into the app /// </summary> /// <param name="systemSettings">System settings</param> /// <param name="userSettings">User settings</param> /// <param name="label">Label to show in the app</param> /// <returns>The Url</returns> public static string GetSecretUrl(MobileAppSystemSettings systemSettings, MobileAppUserSettings userSettings, string label) { return Internal.TotpHelper.GetSecretUrl(userSettings.Secret, label); }
/// <summary> /// Create a new secret for a user /// </summary> /// <param name="systemSettings">System settings</param> /// <returns>New user settings</returns> public static MobileAppUserSettings CreateNewSecret(MobileAppSystemSettings systemSettings) { return new MobileAppUserSettings() { Secret = Internal.TotpHelper.CreateNewSecret(systemSettings.SecretLengthInBits) }; }
/// <summary> /// Check if a code is valid /// </summary> /// <param name="systemSettings">System settings</param> /// <param name="userSettings">User settings</param> /// <param name="code">Code to check</param> /// <returns>True if the code is valid, false if not</returns> public static bool Authenticate(MobileAppSystemSettings systemSettings, MobileAppUserSettings userSettings, int code) { int timestamp = Internal.TotpHelper.TimeStamp; bool valid = Internal.TotpHelper.Authenticate(userSettings.Secret, systemSettings.TimeWindowSize, timestamp, code); return valid && _invalidCodes.CheckAndAdd(code, timestamp, systemSettings.TimeWindowSize); }