Rename .raw to .hash

This commit is contained in:
Ryan Leckey
2013-07-10 10:37:45 -07:00
parent cd5c45c1fc
commit 79965e7293
2 changed files with 8 additions and 8 deletions

View File

@@ -15,18 +15,18 @@ class Password(object):
def __init__(self, value, context=None):
# Store the hash.
self.raw = value
self.hash = value
# Save weakref of the password context (if we have one)
if context is not None:
self.context = weakref.proxy(context)
def __eq__(self, value):
valid, new = self.context.verify_and_update(value, self.raw)
valid, new = self.context.verify_and_update(value, self.hash)
if valid and new:
# New hash was calculated due to various reasons; stored one
# wasn't optimal, etc.
self.raw = new
self.hash = new
return valid
def __ne__(self, value):
@@ -85,7 +85,7 @@ class PasswordType(types.TypeDecorator):
def process_bind_param(self, value, dialect):
if isinstance(value, Password):
# Value has already been hashed.
return value.raw
return value.hash
if isinstance(value, six.string_types):
# Assume value has not been hashed.

View File

@@ -32,8 +32,8 @@ class TestPasswordType(TestCase):
obj = self.User()
obj.password = b'b'
assert obj.password.raw != 'b'
assert obj.password.raw.startswith(b'$pbkdf2-sha512$')
assert obj.password.hash != 'b'
assert obj.password.hash.startswith(b'$pbkdf2-sha512$')
def test_check(self):
"""
@@ -65,6 +65,6 @@ class TestPasswordType(TestCase):
obj = self.User()
obj.password = Password(md5_crypt.encrypt('b'))
assert obj.password.raw.startswith('$1$')
assert obj.password.hash.startswith('$1$')
assert obj.password == 'b'
assert obj.password.raw.startswith('$pbkdf2-sha512$')
assert obj.password.hash.startswith('$pbkdf2-sha512$')