Add password hasher
This commit is contained in:
parent
78e87103ef
commit
c902050055
38
BusinessLogic/Tools/PasswordHasher.cs
Normal file
38
BusinessLogic/Tools/PasswordHasher.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Хеширует с использование SHA256
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="password">Пароль</param>
|
||||||
|
/// <returns>Хеш пароля</returns>
|
||||||
|
public static string Hash(string password)
|
||||||
|
{
|
||||||
|
using (SHA256 sha256 = SHA256.Create())
|
||||||
|
{
|
||||||
|
byte[] bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
|
||||||
|
return Convert.ToBase64String(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверяет на соответствие пароля и его хеша
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="password">Пароль</param>
|
||||||
|
/// <param name="passHash">Хеш пароля</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool Verify(string password, string passHash)
|
||||||
|
{
|
||||||
|
var hash = Hash(password);
|
||||||
|
return hash == passHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user