22 lines
611 B
C#
22 lines
611 B
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace IM_API.Tools
|
|
{
|
|
public static class PasswordHasher
|
|
{
|
|
public static string HashPassword(string password)
|
|
{
|
|
using var sha256 = SHA256.Create();
|
|
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
|
|
return Convert.ToBase64String(hashedBytes);
|
|
}
|
|
|
|
public static bool VerifyPassword(string password, string hashedPassword)
|
|
{
|
|
var hashedInput = HashPassword(password);
|
|
return hashedInput == hashedPassword;
|
|
}
|
|
}
|
|
}
|