PasswordType now falls back to default length (1024) if no schemes were found in crypt context
This commit is contained in:
@@ -88,7 +88,7 @@ class PasswordType(types.TypeDecorator, ScalarCoercible):
|
||||
if max_length is None:
|
||||
# Calculate the largest possible encoded password.
|
||||
# name + rounds + salt + hash + ($ * 4) of largest hash
|
||||
max_lengths = []
|
||||
max_lengths = [1024]
|
||||
for name in self.context.schemes():
|
||||
scheme = getattr(__import__('passlib.hash').hash, name)
|
||||
length = 4 + len(scheme.name)
|
||||
|
@@ -8,7 +8,6 @@ from sqlalchemy_utils import Password, PasswordType
|
||||
|
||||
@mark.skipif('password.passlib is None')
|
||||
class TestPasswordType(TestCase):
|
||||
|
||||
def create_models(self):
|
||||
class User(self.Base):
|
||||
__tablename__ = 'user'
|
||||
@@ -86,3 +85,6 @@ class TestPasswordType(TestCase):
|
||||
expected_length += 4
|
||||
|
||||
assert impl.length == expected_length
|
||||
|
||||
def test_without_schemes(self):
|
||||
assert PasswordType(schemes=[]).length == 1024
|
||||
|
Reference in New Issue
Block a user