From 1f0d4e058085e5b9f3c3852a041d7622ad043251 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Wed, 6 Dec 2023 11:21:37 +0100 Subject: [PATCH] optimize code --- .../Controllers/AuthenticationController.cs | 4 ++-- src/Nager.Authentication/Helpers/InitialUserHelper.cs | 3 +++ src/Nager.Authentication/Helpers/PasswordHelper.cs | 7 +++++-- src/Nager.Authentication/Helpers/RoleHelper.cs | 3 +++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Nager.Authentication.AspNet/Controllers/AuthenticationController.cs b/src/Nager.Authentication.AspNet/Controllers/AuthenticationController.cs index 5f543d4..344c4b6 100644 --- a/src/Nager.Authentication.AspNet/Controllers/AuthenticationController.cs +++ b/src/Nager.Authentication.AspNet/Controllers/AuthenticationController.cs @@ -76,8 +76,8 @@ private async Task CreateTokenAsync( var claims = new List { - new Claim(JwtRegisteredClaimNames.UniqueName, request.EmailAddress), - new Claim(JwtRegisteredClaimNames.Email, request.EmailAddress) + new(JwtRegisteredClaimNames.UniqueName, request.EmailAddress), + new(JwtRegisteredClaimNames.Email, request.EmailAddress) }; if (!string.IsNullOrEmpty(userInfo.Firstname)) diff --git a/src/Nager.Authentication/Helpers/InitialUserHelper.cs b/src/Nager.Authentication/Helpers/InitialUserHelper.cs index c4deb87..2a1fcce 100644 --- a/src/Nager.Authentication/Helpers/InitialUserHelper.cs +++ b/src/Nager.Authentication/Helpers/InitialUserHelper.cs @@ -4,6 +4,9 @@ namespace Nager.Authentication.Helpers { + /// + /// InitialUserHelper + /// public static class InitialUserHelper { public static async Task CreateUsersAsync( diff --git a/src/Nager.Authentication/Helpers/PasswordHelper.cs b/src/Nager.Authentication/Helpers/PasswordHelper.cs index 50abe48..3908b90 100644 --- a/src/Nager.Authentication/Helpers/PasswordHelper.cs +++ b/src/Nager.Authentication/Helpers/PasswordHelper.cs @@ -4,6 +4,9 @@ namespace Nager.Authentication.Helpers { + /// + /// PasswordHelper + /// public static class PasswordHelper { private const int IterationCount = 10_000; @@ -46,9 +49,9 @@ public static byte[] HashPasword(string password, byte[] salt) /// public static string CreateRandomPassword(int length) { - using var rngCryptoServiceProvider = new RNGCryptoServiceProvider(); + using var randomNumberGenerator = RandomNumberGenerator.Create(); var tokenBuffer = new byte[length]; - rngCryptoServiceProvider.GetBytes(tokenBuffer); + randomNumberGenerator.GetBytes(tokenBuffer); return Convert.ToBase64String(tokenBuffer); } } diff --git a/src/Nager.Authentication/Helpers/RoleHelper.cs b/src/Nager.Authentication/Helpers/RoleHelper.cs index 6bafb16..c8c099c 100644 --- a/src/Nager.Authentication/Helpers/RoleHelper.cs +++ b/src/Nager.Authentication/Helpers/RoleHelper.cs @@ -3,6 +3,9 @@ namespace Nager.Authentication.Helpers { + /// + /// RoleHelper + /// public static class RoleHelper { public static char RoleSeperator = ',';