Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        public NewPassword GetPassword(string clearTxtPassword)
        {
            NewPassword np = new NewPassword(clearTxtPassword);

            np.Salt = GetSalt();
            np = HashPassword(np);

            return np;
        }
Exemplo n.º 3
0
        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;
        }