diff options
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/cli/users.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/webmentions_ssg/cli/users.py b/webmentions_ssg/cli/users.py index 7c6afde..a48fc71 100644 --- a/webmentions_ssg/cli/users.py +++ b/webmentions_ssg/cli/users.py @@ -10,6 +10,7 @@ from flask.cli import AppGroup from sqlalchemy.exc import IntegrityError from .. import DATABASE +from ..security import validate_password USERS_CLI = AppGroup("users", help="Manage users.") @@ -41,8 +42,10 @@ def create_user(username: str, password: str) -> None: if not username: raise click.ClickException("Username must not be empty.") - if not password: - raise click.ClickException("Password must not be empty.") + try: + validate_password(password) + except ValueError as exc: + raise click.ClickException(str(exc)) from exc if DATABASE.session.scalar(sa.select(User).where(User.username == username)): raise click.ClickException(f"User {username!r} already exists.") @@ -81,10 +84,12 @@ def set_user_password(username: str, password: str) -> None: :param username: Username of the account to update. :param password: New plain-text password to hash and store. - :raises click.ClickException: If the account is missing or the password is empty. + :raises click.ClickException: If the account is missing or the password is invalid. """ - if not password: - raise click.ClickException("Password must not be empty.") + try: + validate_password(password) + except ValueError as exc: + raise click.ClickException(str(exc)) from exc user = _require_user(username) user.password = password |
