mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-14 22:45:47 +00:00
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:
@ -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)
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user