Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions _practices/safe-password-storage/_python/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(self, salt=None, pepper=None, rounds=None):

def encode(self, password):
if self.salt is None:
return hashlib.md5(password).hexdigest()
# Added encode() to handle TypeError: Unicode-objects must be encoded before hashing
return hashlib.md5(password.encode()).hexdigest()
elif self.salt == 'same':
salt = self.global_salt
elif self.salt == 'user':
Expand Down Expand Up @@ -67,7 +68,8 @@ def __init__(self, salt=None, pepper=None, rounds=None):
raise NotImplementedError("BCRYPT NEEDS A SALT MORON")

self.salt = salt
self.pepper = pepper
# Added encode() to handle TypeError: can only concatenate str (not "bytes") to str
self.pepper = pepper.encode()

def encode(self, password):
if self.salt == 'same':
Expand Down