|
|
|
@ -1,27 +1,34 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Model
|
|
|
|
|
{
|
|
|
|
|
[DataContract(Name = "passmgr")]
|
|
|
|
|
public class PasswordManager : IPasswordManager
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public int HashPassword(string password)
|
|
|
|
|
public string HashPassword(string password)
|
|
|
|
|
{
|
|
|
|
|
int hashedPassword = password.GetHashCode();
|
|
|
|
|
return hashedPassword;
|
|
|
|
|
byte[] data;
|
|
|
|
|
using (SHA256 sha256Hash = SHA256.Create())
|
|
|
|
|
data = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(password));
|
|
|
|
|
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
foreach (byte b in data) sb.Append(b.ToString("x2"));
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool VerifyPassword(int hashedPassword, string passwordEntered )
|
|
|
|
|
public bool VerifyPassword(string hashedPassword, string passwordEntered)
|
|
|
|
|
{
|
|
|
|
|
int passwordEnteredHashed = passwordEntered.GetHashCode();
|
|
|
|
|
if ( passwordEnteredHashed == hashedPassword)
|
|
|
|
|
return true;
|
|
|
|
|
else return false;
|
|
|
|
|
string hashedInput = HashPassword(passwordEntered);
|
|
|
|
|
StringComparer strcmp = StringComparer.OrdinalIgnoreCase;
|
|
|
|
|
|
|
|
|
|
return strcmp.Compare(hashedPassword, hashedInput) == 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|