private NewPassword HashPassword(NewPassword np) { HashAlgorithm hashAlg = null; try { hashAlg = new SHA256CryptoServiceProvider(); byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(np.GetSaltPassword()); byte[] bytHash = hashAlg.ComputeHash(bytValue); np.SaltedHashedPassword = Convert.ToBase64String(bytHash); } catch (Exception e) { throw e; } finally { if (hashAlg != null) { hashAlg.Clear(); hashAlg.Dispose(); hashAlg = null; } } return np; }
public NewPassword GetPassword(string clearTxtPassword) { NewPassword np = new NewPassword(clearTxtPassword); np.Salt = GetSalt(); np = HashPassword(np); return np; }
private bool ComparePasswords(User u, string suppliedPass) { bool goodUser = false; NewPassword np = new NewPassword(suppliedPass); np.Salt = u.Salt; np = HashPassword(np); if (u.Password.Equals(np.SaltedHashedPassword)) goodUser = true; return goodUser; }