summaryrefslogtreecommitdiff
path: root/docs/tutorials/wiki/src
diff options
context:
space:
mode:
authorMartin <martin.frlin@gmail.com>2016-12-07 09:43:22 +0100
committerMartin <martin.frlin@gmail.com>2016-12-07 09:43:22 +0100
commitb4abcd1f596297eb083e855d5e9a158d9e108c81 (patch)
treec8821106aa2c04610f916703d02eda509f787f93 /docs/tutorials/wiki/src
parentb01a0233aa03b4b5a9ddd640a7a114f68d1c763d (diff)
downloadpyramid-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')
-rw-r--r--docs/tutorials/wiki/src/authorization/tutorial/security.py6
-rw-r--r--docs/tutorials/wiki/src/tests/tutorial/security.py6
2 files changed, 8 insertions, 4 deletions
diff --git a/docs/tutorials/wiki/src/authorization/tutorial/security.py b/docs/tutorials/wiki/src/authorization/tutorial/security.py
index 4115c780c..cbb3acd5d 100644
--- a/docs/tutorials/wiki/src/authorization/tutorial/security.py
+++ b/docs/tutorials/wiki/src/authorization/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'),
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'),