2024-06-05 15:13:27 +04:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Хеширует с использование SHA256
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="password">Пароль</param>
|
|
|
|
|
/// <returns>Хеш пароля</returns>
|
|
|
|
|
public static string Hash(string password)
|
|
|
|
|
{
|
2024-06-06 17:50:42 +04:00
|
|
|
|
return BCrypt.Net.BCrypt.HashPassword(password);
|
2024-06-05 15:13:27 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Проверяет на соответствие пароля и его хеша
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="password">Пароль</param>
|
|
|
|
|
/// <param name="passHash">Хеш пароля</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool Verify(string password, string passHash)
|
|
|
|
|
{
|
2024-06-06 17:50:42 +04:00
|
|
|
|
return BCrypt.Net.BCrypt.Verify(password, passHash);
|
2024-06-05 15:13:27 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|