Skip to content

Commit

Permalink
[Register][Hai] generate digti otp
Browse files Browse the repository at this point in the history
  • Loading branch information
HaiHungNguyenn committed Mar 20, 2024
1 parent 8dd4cf9 commit 1a44ad2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Domus.Common/Helpers/RandomPasswordHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ public static string GenerateRandomPassword(int length)
.ToArray()
.Append(sepecialChars[_random.Next(sepecialChars.Length)]).ToArray());
}
public static string GenerateRandomDigitPassword(int length)
{
const string digits = "0123456789";
return new string(Enumerable.Repeat(digits, length)
.Select(s => s[_random.Next(s.Length)])
.ToArray());
}
}
2 changes: 1 addition & 1 deletion Domus.Service/Implementations/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public async Task<ServiceActionResult> RegisterAsync(RegisterRequest request)
UserId = retrievedUser.Id,
Used = false,
CreatedAt= DateTime.Now.AddHours(7),
Code = RandomPasswordHelper.GenerateRandomPassword(10)
Code = RandomPasswordHelper.GenerateRandomDigitPassword(4)
};
await _otpRepository.AddAsync(otp);
await _unitOfWork.CommitAsync();
Expand Down

0 comments on commit 1a44ad2

Please sign in to comment.