From 3267acbeb3fcc44a3b77255c4bcff87b88c752af Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Sat, 25 Jan 2025 00:35:19 +0100 Subject: [PATCH] =?UTF-8?q?feat(CodeGenerator):=20GenerateTotp=20und=20Ver?= =?UTF-8?q?ifyTotp=20Methoden=20hinzugef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contracts/ICodeGenerator.cs | 14 ++- .../EnvelopeGenerator.Application.csproj | 101 +++++++++--------- .../Services/CodeGenerator.cs | 5 + 3 files changed, 66 insertions(+), 54 deletions(-) diff --git a/EnvelopeGenerator.Application/Contracts/ICodeGenerator.cs b/EnvelopeGenerator.Application/Contracts/ICodeGenerator.cs index 38a27b85..d4e93c6b 100644 --- a/EnvelopeGenerator.Application/Contracts/ICodeGenerator.cs +++ b/EnvelopeGenerator.Application/Contracts/ICodeGenerator.cs @@ -1,13 +1,19 @@ -namespace EnvelopeGenerator.Application.Contracts +using OtpNet; + +namespace EnvelopeGenerator.Application.Contracts { public interface ICodeGenerator { string GenerateCode(int length); - public string GenerateTotpSecretKey(int? length = null); + string GenerateTotpSecretKey(int? length = null); + + byte[] GenerateTotpQrCode(string userEmail, string secretKey, string? issuer = null, string? totpUrlFormat = null, int? pixelsPerModule = null); + + byte[] GenerateTotpQrCode(string userEmail, int? length = null, string? issuer = null, string? totpUrlFormat = null, int? pixelsPerModule = null); - public byte[] GenerateTotpQrCode(string userEmail, string secretKey, string? issuer = null, string? totpUrlFormat = null, int? pixelsPerModule = null); + string GenerateTotp(string secretKey, int step = 30); - public byte[] GenerateTotpQrCode(string userEmail, int? length = null, string? issuer = null, string? totpUrlFormat = null, int? pixelsPerModule = null); + bool VerifyTotp(string totpCode, string secretKey, int step = 30, VerificationWindow? window = null); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj b/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj index 6032bb17..c16b447f 100644 --- a/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj +++ b/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj @@ -1,59 +1,60 @@  - - net7.0 - enable - enable - + + net7.0 + enable + enable + - - - + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - True - True - Model.resx - - + + + True + True + Model.resx + + - - - My.Resources - Model.en.Designer.vb - PublicResXFileCodeGenerator - - - My.Resources - Model.Designer.cs - PublicResXFileCodeGenerator - - - PreserveNewest - - - PreserveNewest - - + + + My.Resources + Model.en.Designer.vb + PublicResXFileCodeGenerator + + + My.Resources + Model.Designer.cs + PublicResXFileCodeGenerator + + + PreserveNewest + + + PreserveNewest + + diff --git a/EnvelopeGenerator.Application/Services/CodeGenerator.cs b/EnvelopeGenerator.Application/Services/CodeGenerator.cs index 89d22522..ca84bfc9 100644 --- a/EnvelopeGenerator.Application/Services/CodeGenerator.cs +++ b/EnvelopeGenerator.Application/Services/CodeGenerator.cs @@ -62,5 +62,10 @@ namespace EnvelopeGenerator.Application.Services totpUrlFormat: totpUrlFormat, pixelsPerModule: pixelsPerModule); } + + public string GenerateTotp(string secretKey, int step = 30) => new Totp(Base32Encoding.ToBytes(secretKey), step).ComputeTotp(); + + public bool VerifyTotp(string totpCode, string secretKey, int step = 30, VerificationWindow? window = null) + => new Totp(Base32Encoding.ToBytes(secretKey), step).VerifyTotp(totpCode, out _, window); } } \ No newline at end of file