Files
universidad-en-asp.net/Utils/PasswordHash.cs
Daniel Cortés 3132ecc900 Initial Commit
2019-12-12 04:06:08 -03:00

32 lines
911 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Utils
{
public class PasswordHash
{
// No es perfecto, pero me tengo un limite de 15 caracteres en la base de datos
// y realmente no queria guardar contraseñas en texto plano
public static string Hash(string password)
{
using (SHA1Managed sha1 = new SHA1Managed())
{
var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(password));
return Convert.ToBase64String(hash).Truncate(15);
}
}
public static bool Compare(string password, string hashed)
{
if (password == null) return false;
if (hashed == null) return false;
return Hash(password).Equals(hashed);
}
}
}