Iceshrimp.NET/Iceshrimp.Backend/Core/Helpers/TotpHelper.cs
2025-01-08 18:09:12 +01:00

14 lines
423 B
C#

using OtpNet;
namespace Iceshrimp.Backend.Core.Helpers;
public static class TotpHelper
{
private static readonly VerificationWindow VerificationWindow = new(1, 1);
public static bool Validate(string secret, string totp)
=> new Totp(Base32Encoding.ToBytes(secret)).VerifyTotp(totp, out _, VerificationWindow);
public static string GenerateSecret()
=> Base32Encoding.ToString(KeyGeneration.GenerateRandomKey());
}