feat: give the user the ability to make a password policy

This commit is contained in:
2024-12-18 07:27:57 +03:00
parent 598ebabc5c
commit e760ddae0a
8 changed files with 159 additions and 17 deletions

View File

@ -1,11 +1,10 @@
using Konscious.Security.Cryptography;
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace Mirea.Api.Security.Services;
public partial class PasswordHashService
public class PasswordHashService
{
public int SaltSize { private get; init; }
public int HashSize { private get; init; }
@ -54,15 +53,4 @@ public partial class PasswordHashService
public bool VerifyPassword(string password, string saltBase64, string hashBase64) =>
VerifyPassword(password, Convert.FromBase64String(saltBase64), Convert.FromBase64String(hashBase64));
public static bool HasPasswordInPolicySecurity(string password) =>
password.Length >= 8 &&
PasswordExistSpecialSymbol().IsMatch(password) &&
PasswordExistUpperLetter().IsMatch(password);
[GeneratedRegex("[A-Z]+")]
private static partial Regex PasswordExistUpperLetter();
[GeneratedRegex("[!@#$%^&*]+")]
private static partial Regex PasswordExistSpecialSymbol();
}