ask users to repeat password

In case if password is asked via getpass, it is possible to make typo
and user will not see the mistake. In order to avoid it, additional
confirmation has been added
This commit is contained in:
2022-11-22 02:19:37 +02:00
parent 14cb548c3b
commit 81fa73f725
3 changed files with 41 additions and 5 deletions

View File

@ -26,6 +26,7 @@ from typing import Type
from ahriman.application.handlers import Handler
from ahriman.core.configuration import Configuration
from ahriman.core.database import SQLite
from ahriman.core.exceptions import PasswordError
from ahriman.core.formatters import UserPrinter
from ahriman.models.action import Action
from ahriman.models.user import User
@ -149,7 +150,15 @@ class Users(Handler):
Returns:
User: built user descriptor
"""
def read_password() -> str:
first_password = getpass.getpass()
second_password = getpass.getpass("Repeat password: ")
if first_password != second_password:
raise PasswordError("passwords don't match")
return first_password
password = args.password
if password is None:
password = getpass.getpass()
password = read_password()
return User(username=args.username, password=password, access=args.role)

View File

@ -179,6 +179,21 @@ class PathError(ValueError):
ValueError.__init__(self, f"Path `{path}` does not belong to repository root `{root}`")
class PasswordError(ValueError):
"""
exception which will be raised in case of password related errors
"""
def __init__(self, details: Any) -> None:
"""
default constructor
Args:
details(Any); error details
"""
ValueError.__init__(self, f"Password error: {details}")
class ReportError(RuntimeError):
"""
report generation exception