diff options
| author | Martin <martin.frlin@gmail.com> | 2016-12-07 09:43:22 +0100 |
|---|---|---|
| committer | Martin <martin.frlin@gmail.com> | 2016-12-07 09:43:22 +0100 |
| commit | b4abcd1f596297eb083e855d5e9a158d9e108c81 (patch) | |
| tree | c8821106aa2c04610f916703d02eda509f787f93 /docs/tutorials/wiki/src/tests | |
| parent | b01a0233aa03b4b5a9ddd640a7a114f68d1c763d (diff) | |
| download | pyramid-b4abcd1f596297eb083e855d5e9a158d9e108c81.tar.gz pyramid-b4abcd1f596297eb083e855d5e9a158d9e108c81.tar.bz2 pyramid-b4abcd1f596297eb083e855d5e9a158d9e108c81.zip | |
Hashing helpers now deal in unicode. Fixed wording. Added link to bcrypt and a footnote from wiki2 example.
Diffstat (limited to 'docs/tutorials/wiki/src/tests')
| -rw-r--r-- | docs/tutorials/wiki/src/tests/tutorial/security.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/docs/tutorials/wiki/src/tests/tutorial/security.py b/docs/tutorials/wiki/src/tests/tutorial/security.py index 4115c780c..cbb3acd5d 100644 --- a/docs/tutorials/wiki/src/tests/tutorial/security.py +++ b/docs/tutorials/wiki/src/tests/tutorial/security.py @@ -2,11 +2,13 @@ import bcrypt def hash_password(pw): - return bcrypt.hashpw(pw.encode('utf-8'), bcrypt.gensalt()) + hashed_pw = bcrypt.hashpw(pw.encode('utf-8'), bcrypt.gensalt()) + # return unicode instead of bytes because databases handle it better + return hashed_pw.decode('utf-8') def check_password(expected_hash, pw): if expected_hash is not None: - return bcrypt.checkpw(pw.encode('utf-8'), expected_hash) + return bcrypt.checkpw(pw.encode('utf-8'), expected_hash.encode('utf-8')) return False USERS = {'editor': hash_password('editor'), |
