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; } } }