Polianin Nikita
cd6f25deba
All logic related to token manipulation has been transferred to the AuthService. Also added TOTP 2FA and rethought the logic of logging into the application
20 lines
450 B
C#
20 lines
450 B
C#
using OtpNet;
|
|
|
|
namespace Mirea.Api.Security.Services;
|
|
|
|
public class TotpService
|
|
{
|
|
private readonly Totp _totp;
|
|
|
|
public TotpService(string secret)
|
|
{
|
|
var secretBytes = Base32Encoding.ToBytes(secret);
|
|
_totp = new Totp(secretBytes);
|
|
}
|
|
|
|
public string GenerateToken() =>
|
|
_totp.ComputeTotp();
|
|
|
|
public bool VerifyToken(string token) =>
|
|
_totp.VerifyTotp(token, out _, new VerificationWindow(2, 2));
|
|
} |