From c902050055559b79de7ecb16b93ca842cd73f9e8 Mon Sep 17 00:00:00 2001 From: mfnefd Date: Wed, 5 Jun 2024 15:13:27 +0400 Subject: [PATCH] Add password hasher --- BusinessLogic/Tools/PasswordHasher.cs | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 BusinessLogic/Tools/PasswordHasher.cs diff --git a/BusinessLogic/Tools/PasswordHasher.cs b/BusinessLogic/Tools/PasswordHasher.cs new file mode 100644 index 0000000..f73edca --- /dev/null +++ b/BusinessLogic/Tools/PasswordHasher.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.Tools +{ + internal class PasswordHasher + { + /// + /// Хеширует с использование SHA256 + /// + /// Пароль + /// Хеш пароля + public static string Hash(string password) + { + using (SHA256 sha256 = SHA256.Create()) + { + byte[] bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(password)); + return Convert.ToBase64String(bytes); + } + } + + /// + /// Проверяет на соответствие пароля и его хеша + /// + /// Пароль + /// Хеш пароля + /// + public static bool Verify(string password, string passHash) + { + var hash = Hash(password); + return hash == passHash; + } + } +} \ No newline at end of file