summaryrefslogtreecommitdiff
path: root/docs/quick_tutorial/authentication/tutorial
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2016-09-28 20:38:15 -0500
committerMichael Merickel <michael@merickel.org>2016-09-28 20:38:15 -0500
commit8ce5736478f035cc14cfd247e7d936dc4db1f7b5 (patch)
tree48d48dc3433e915df60d2549cebab64762fdd4fd /docs/quick_tutorial/authentication/tutorial
parente8c66a339e9f7d83bd2408952de53ef30dba0794 (diff)
parent7391d365ce68677c588cf60c1431d29a786c6e82 (diff)
downloadpyramid-8ce5736478f035cc14cfd247e7d936dc4db1f7b5.tar.gz
pyramid-8ce5736478f035cc14cfd247e7d936dc4db1f7b5.tar.bz2
pyramid-8ce5736478f035cc14cfd247e7d936dc4db1f7b5.zip
Merge branch 'master' into exception_only
Diffstat (limited to 'docs/quick_tutorial/authentication/tutorial')
-rw-r--r--docs/quick_tutorial/authentication/tutorial/security.py16
-rw-r--r--docs/quick_tutorial/authentication/tutorial/views.py7
2 files changed, 19 insertions, 4 deletions
diff --git a/docs/quick_tutorial/authentication/tutorial/security.py b/docs/quick_tutorial/authentication/tutorial/security.py
index ab90bab2c..e585e2642 100644
--- a/docs/quick_tutorial/authentication/tutorial/security.py
+++ b/docs/quick_tutorial/authentication/tutorial/security.py
@@ -1,5 +1,17 @@
-USERS = {'editor': 'editor',
- 'viewer': 'viewer'}
+import bcrypt
+
+
+def hash_password(pw):
+ pwhash = bcrypt.hashpw(pw.encode('utf8'), bcrypt.gensalt())
+ return pwhash.decode('utf8')
+
+def check_password(pw, hashed_pw):
+ expected_hash = hashed_pw.encode('utf8')
+ return bcrypt.checkpw(pw.encode('utf8'), expected_hash)
+
+
+USERS = {'editor': hash_password('editor'),
+ 'viewer': hash_password('viewer')}
GROUPS = {'editor': ['group:editors']}
diff --git a/docs/quick_tutorial/authentication/tutorial/views.py b/docs/quick_tutorial/authentication/tutorial/views.py
index ab46eb2dd..b07538d5e 100644
--- a/docs/quick_tutorial/authentication/tutorial/views.py
+++ b/docs/quick_tutorial/authentication/tutorial/views.py
@@ -9,7 +9,10 @@ from pyramid.view import (
view_defaults
)
-from .security import USERS
+from .security import (
+ USERS,
+ check_password
+)
@view_defaults(renderer='home.pt')
@@ -40,7 +43,7 @@ class TutorialViews:
if 'form.submitted' in request.params:
login = request.params['login']
password = request.params['password']
- if USERS.get(login) == password:
+ if check_password(password, USERS.get(login)):
headers = remember(request, login)
return HTTPFound(location=came_from,
headers=headers)