示例#1
0
文件: Password.cs 项目: ehelin/TGIMBA
        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;
        }
示例#2
0
文件: Password.cs 项目: ehelin/TGIMBA
        public NewPassword GetPassword(string clearTxtPassword)
        {
            NewPassword np = new NewPassword(clearTxtPassword);

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

            return np;
        }
示例#3
0
文件: Password.cs 项目: ehelin/TGIMBA
        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;
        }