diff options
| author | Michael Merickel <michael@merickel.org> | 2016-02-14 17:35:01 -0600 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2016-02-14 17:35:01 -0600 |
| commit | 42c93166fbe676341b1d94ec3659ae772dd073d8 (patch) | |
| tree | 5de468a7041d11f6f46636ed9a4cf27f3c1f6188 /docs/tutorials/wiki2 | |
| parent | bca6c996d9e879c21d8b207bb36bc10ebe1db256 (diff) | |
| download | pyramid-42c93166fbe676341b1d94ec3659ae772dd073d8.tar.gz pyramid-42c93166fbe676341b1d94ec3659ae772dd073d8.tar.bz2 pyramid-42c93166fbe676341b1d94ec3659ae772dd073d8.zip | |
fix unicode issues with check_password
Diffstat (limited to 'docs/tutorials/wiki2')
| -rw-r--r-- | docs/tutorials/wiki2/src/models/tutorial/models/user.py | 6 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/views/tutorial/models/user.py | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/docs/tutorials/wiki2/src/models/tutorial/models/user.py b/docs/tutorials/wiki2/src/models/tutorial/models/user.py index 25b0a8187..6fb32a1b2 100644 --- a/docs/tutorials/wiki2/src/models/tutorial/models/user.py +++ b/docs/tutorials/wiki2/src/models/tutorial/models/user.py @@ -18,10 +18,12 @@ class User(Base): password_hash = Column(Text) def set_password(self, pw): - pwhash = bcrypt.hashpw(pw, bcrypt.gensalt()) + pwhash = bcrypt.hashpw(pw.encode('utf8'), bcrypt.gensalt()) self.password_hash = pwhash def check_password(self, pw): if self.password_hash is not None: - return bcrypt.hashpw(pw, self.password_hash) == self.password_hash + expected_hash = self.password_hash.encode('utf8') + actual_hash = bcrypt.hashpw(pw.encode('utf8'), expected_hash) + return expected_hash == actual_hash return False diff --git a/docs/tutorials/wiki2/src/views/tutorial/models/user.py b/docs/tutorials/wiki2/src/views/tutorial/models/user.py index 25b0a8187..6fb32a1b2 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/models/user.py +++ b/docs/tutorials/wiki2/src/views/tutorial/models/user.py @@ -18,10 +18,12 @@ class User(Base): password_hash = Column(Text) def set_password(self, pw): - pwhash = bcrypt.hashpw(pw, bcrypt.gensalt()) + pwhash = bcrypt.hashpw(pw.encode('utf8'), bcrypt.gensalt()) self.password_hash = pwhash def check_password(self, pw): if self.password_hash is not None: - return bcrypt.hashpw(pw, self.password_hash) == self.password_hash + expected_hash = self.password_hash.encode('utf8') + actual_hash = bcrypt.hashpw(pw.encode('utf8'), expected_hash) + return expected_hash == actual_hash return False |
