Initial Commit

This commit is contained in:
Daniel Cortés
2019-12-12 04:06:08 -03:00
commit 3132ecc900
36 changed files with 3190 additions and 0 deletions

31
Utils/PasswordHash.cs Normal file
View File

@@ -0,0 +1,31 @@
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);
}
}
}