diff --git a/server/szurubooru/func/auth.py b/server/szurubooru/func/auth.py index 55b4db39..c9740fe0 100644 --- a/server/szurubooru/func/auth.py +++ b/server/szurubooru/func/auth.py @@ -1,13 +1,11 @@ from typing import Tuple - import hashlib import random from collections import OrderedDict +from nacl import pwhash from nacl.exceptions import InvalidkeyError - from szurubooru import config, model, errors, db from szurubooru.func import util -from nacl import pwhash RANK_MAP = OrderedDict([ diff --git a/server/szurubooru/func/users.py b/server/szurubooru/func/users.py index 2b744e28..5fe9f2ca 100644 --- a/server/szurubooru/func/users.py +++ b/server/szurubooru/func/users.py @@ -243,8 +243,10 @@ def update_user_password(user: model.User, password: str) -> None: raise InvalidPasswordError( 'Password must satisfy regex %r.' % password_regex) user.password_salt = auth.create_password() - hash, revision = auth.get_password_hash(user.password_salt, password) - user.password_hash = hash + password_hash, revision = auth.get_password_hash( + user.password_salt, + password) + user.password_hash = password_hash user.password_revision = revision diff --git a/server/szurubooru/migrations/env.py b/server/szurubooru/migrations/env.py index 61b20f4e..59d031f6 100644 --- a/server/szurubooru/migrations/env.py +++ b/server/szurubooru/migrations/env.py @@ -38,8 +38,7 @@ def run_migrations_offline(): url=url, target_metadata=target_metadata, literal_binds=True, - compare_type=True - ) + compare_type=True) with alembic.context.begin_transaction(): alembic.context.run_migrations() @@ -61,8 +60,7 @@ def run_migrations_online(): alembic.context.configure( connection=connection, target_metadata=target_metadata, - compare_type=True - ) + compare_type=True) with alembic.context.begin_transaction(): alembic.context.run_migrations() diff --git a/server/szurubooru/migrations/versions/9ef1a1643c2a_update_user_table_for_hardened_passwords.py b/server/szurubooru/migrations/versions/9ef1a1643c2a_update_user_table_for_hardened_passwords.py index 33aa9c93..084f196e 100644 --- a/server/szurubooru/migrations/versions/9ef1a1643c2a_update_user_table_for_hardened_passwords.py +++ b/server/szurubooru/migrations/versions/9ef1a1643c2a_update_user_table_for_hardened_passwords.py @@ -47,14 +47,17 @@ class User(Base): def upgrade(): - op.alter_column('user', 'password_hash', - existing_type=sa.VARCHAR(length=64), - type_=sa.Unicode(length=128), - existing_nullable=False) - op.add_column('user', sa.Column('password_revision', - sa.SmallInteger(), - nullable=True, - default=0)) + op.alter_column( + 'user', + 'password_hash', + existing_type=sa.VARCHAR(length=64), + type_=sa.Unicode(length=128), + existing_nullable=False) + op.add_column('user', sa.Column( + 'password_revision', + sa.SmallInteger(), + nullable=True, + default=0)) session = sa.orm.session.Session(bind=op.get_bind()) if session.query(User).count() >= 0: @@ -69,13 +72,18 @@ def upgrade(): session.flush() session.commit() - op.alter_column('user', 'password_revision', - existing_nullable=True, nullable=False) + op.alter_column( + 'user', + 'password_revision', + existing_nullable=True, + nullable=False) def downgrade(): - op.alter_column('user', 'password_hash', - existing_type=sa.Unicode(length=128), - type_=sa.VARCHAR(length=64), - existing_nullable=False) + op.alter_column( + 'user', + 'password_hash', + existing_type=sa.Unicode(length=128), + type_=sa.VARCHAR(length=64), + existing_nullable=False) op.drop_column('user', 'password_revision') diff --git a/server/szurubooru/model/user.py b/server/szurubooru/model/user.py index be95b0b1..39c5a91b 100644 --- a/server/szurubooru/model/user.py +++ b/server/szurubooru/model/user.py @@ -25,8 +25,8 @@ class User(Base): name = sa.Column('name', sa.Unicode(50), nullable=False, unique=True) password_hash = sa.Column('password_hash', sa.Unicode(128), nullable=False) password_salt = sa.Column('password_salt', sa.Unicode(32)) - password_revision = sa.Column('password_revision', sa.SmallInteger, - default=0, nullable=False) + password_revision = sa.Column( + 'password_revision', sa.SmallInteger, default=0, nullable=False) email = sa.Column('email', sa.Unicode(64), nullable=True) rank = sa.Column('rank', sa.Unicode(32), nullable=False) avatar_style = sa.Column( diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py index 44ded329..db7806e8 100644 --- a/server/szurubooru/tests/conftest.py +++ b/server/szurubooru/tests/conftest.py @@ -115,11 +115,12 @@ def config_injector(): @pytest.fixture def user_factory(): - def factory(name=None, - rank=model.User.RANK_REGULAR, - email='dummy', - password_salt=None, - password_hash=None): + def factory( + name=None, + rank=model.User.RANK_REGULAR, + email='dummy', + password_salt=None, + password_hash=None): user = model.User() user.name = name or get_unique_name() user.password_salt = password_salt or 'dummy'