Skip to content

Commit

Permalink
add OTP retry minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
emrecoskun705 committed Sep 13, 2023
1 parent c605652 commit 3e6fc14
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public record EmailOtpSettings
{
public string Name { get; init; } = string.Empty;
public int RetryCount { get; init; }
public int OtpRetryMinutes { get; init; }
}
12 changes: 6 additions & 6 deletions Unitagram.Identity/Services/EmailVerificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public async Task<Result<bool>> ValidateAsync(Guid userId, string token)
private string GenerateRandom6DigitCode()
{
using var rng = RandomNumberGenerator.Create();
var bytes = new byte[4]; // Dört bayt uzunluğunda bir dizi oluşturuyoruz.
rng.GetBytes(bytes); // Rastgele baytları dolduruyoruz.
int code = BitConverter.ToInt32(bytes, 0) % 1000000; // 6 haneli bir sayı üretiyoruz.
if (code < 0) code *= -1; // Negatif bir sayıyı pozitife çeviriyoruz.
var bytes = new byte[4]; // Create bytes in length 4.
rng.GetBytes(bytes); // fill bytes randomly.
int code = BitConverter.ToInt32(bytes, 0) % 1000000; // create 6 digit code.
if (code < 0) code *= -1; // if it is negative make it positive.
return code.ToString("D6"); // Format as a 6-digit string
}
private bool IsRetryTimeElapsed(OtpConfirmation otpConfirmation)
Expand All @@ -137,7 +137,7 @@ private double CalculateMinutesDifference(DateTimeOffset retryDateTime)

private async Task CreateOtpConfirmation(Guid userId, string purpose, string token)
{
var retryDateTime = DateTimeOffset.Now.AddMinutes(15);
var retryDateTime = DateTimeOffset.Now.AddMinutes(_emailOtpSettings.OtpRetryMinutes);
var otpConfirmation = new OtpConfirmation()
{
UserId = userId,
Expand All @@ -152,7 +152,7 @@ private async Task CreateOtpConfirmation(Guid userId, string purpose, string tok

private async Task UpdateOtpConfirmation(Guid userId, string purpose, string token)
{
var retryDateTime = DateTimeOffset.Now.AddMinutes(15);
var retryDateTime = DateTimeOffset.Now.AddMinutes(_emailOtpSettings.OtpRetryMinutes);
var otpConfirmation = new OtpConfirmation()
{
UserId = userId,
Expand Down
3 changes: 2 additions & 1 deletion Unitagram.WebAPI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"EmailOtpSettings": {
"Name": "emailverification",
"RetryCount": 7
"RetryCount": 7,
"OtpRetryMinutes": 15
},
"Serilog": {
"MinimumLevel": "Error",
Expand Down

0 comments on commit 3e6fc14

Please sign in to comment.