Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #907 from KentShikama/pepper
Browse files Browse the repository at this point in the history
Add pepper to password hashing
  • Loading branch information
erikjohnston authored Jul 5, 2016
2 parents 3de8168 + 252ee2d commit e34cb5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions synapse/config/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ class PasswordConfig(Config):
def read_config(self, config):
password_config = config.get("password_config", {})
self.password_enabled = password_config.get("enabled", True)
self.password_pepper = password_config.get("pepper", "")

def default_config(self, config_dir_path, server_name, **kwargs):
return """
# Enable password for login.
password_config:
enabled: true
# Change to a secret random string.
# DO NOT CHANGE THIS AFTER INITIAL SETUP!
#pepper: ""
"""
6 changes: 4 additions & 2 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ def hash(self, password):
Returns:
Hashed password (str).
"""
return bcrypt.hashpw(password, bcrypt.gensalt(self.bcrypt_rounds))
return bcrypt.hashpw(password + self.hs.config.password_pepper,
bcrypt.gensalt(self.bcrypt_rounds))

def validate_hash(self, password, stored_hash):
"""Validates that self.hash(password) == stored_hash.
Expand All @@ -763,6 +764,7 @@ def validate_hash(self, password, stored_hash):
Whether self.hash(password) == stored_hash (bool).
"""
if stored_hash:
return bcrypt.hashpw(password, stored_hash.encode('utf-8')) == stored_hash
return bcrypt.hashpw(password + self.hs.config.password_pepper,
stored_hash.encode('utf-8')) == stored_hash
else:
return False

0 comments on commit e34cb5e

Please sign in to comment.