hMailServer.Crypto.Salter.ValidateHash C# (CSharp) Method

ValidateHash() public method

public ValidateHash ( string password, string originalHash ) : bool
password string
originalHash string
return bool
        public bool ValidateHash(string password, string originalHash)
        {
            string salt = originalHash.Substring(0, SaltLength);

            string newHash = salt + Sha256(salt + password);

            if (newHash == originalHash)
                return true;

            return false;
        }

Usage Example

        public async Task<Account> ValidatePasswordAsync(string username, string password)
        {
            using (var sqlConnection = new MySqlConnection(_connectionString))
            {
                sqlConnection.Open();

                var accounts = await sqlConnection.QueryAsync<Account>("SELECT * FROM hm_accounts WHERE accountaddress = @accountaddress", new
                {
                    accountaddress = username
                });

                var account = accounts.SingleOrDefault();

                if (account == null)
                    return null;

                // TODO: Support old hashing methods.
                var salter = new Salter();
                if (salter.ValidateHash(password, account.Password))
                    return account;

                return null;
            }
        }