From de541fc8cab5d682f8c5d7655e2ee4472fcb4e70 Mon Sep 17 00:00:00 2001 From: sebastien yaal Date: Wed, 8 Jan 2025 09:25:06 +0000 Subject: [PATCH] password-hashing-configuration --- CHANGES.rst | 5 +++++ canaille/backends/sql/configuration.py | 7 +++++++ canaille/backends/sql/models.py | 7 ++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index ce8f3397..8ba958a7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,11 @@ Added ^^^^^ - ``--version`` option to the CLI. :pr:`209` +- :attr:`~canaille.backends.sql.configuration.SQLSettings.PASSWORD_SCHEMES` :issue:`175` + +Changed +^^^^^^^ +- fixed a bug on updating user's settings :issue:`206` Changed ^^^^^^^ diff --git a/canaille/backends/sql/configuration.py b/canaille/backends/sql/configuration.py index 8e137539..160be45d 100644 --- a/canaille/backends/sql/configuration.py +++ b/canaille/backends/sql/configuration.py @@ -15,3 +15,10 @@ class SQLSettings(BaseModel): DATABASE_URI = "postgresql://user:password@localhost/database_name" """ + + PASSWORD_SCHEMES: str = "pbkdf2_sha512" + """Password hashing scheme. + + Defines password hashing scheme in SQL database. + examples : "mssql2000", "ldap_salted_sha1", "pbkdf2_sha512" + """ diff --git a/canaille/backends/sql/models.py b/canaille/backends/sql/models.py index a59a44d9..8fd627a6 100644 --- a/canaille/backends/sql/models.py +++ b/canaille/backends/sql/models.py @@ -74,7 +74,12 @@ class User(canaille.core.models.User, Base, SqlAlchemyModel): ) user_name: Mapped[str] = mapped_column(String, unique=True, nullable=False) password: Mapped[str] = mapped_column( - PasswordType(schemes=["pbkdf2_sha512"]), nullable=True + PasswordType( + onload=lambda **kwargs: dict( + schemes=current_app.config["CANAILLE_SQL"]["PASSWORD_SCHEMES"], **kwargs + ), + ), + nullable=True, ) password_last_update: Mapped[datetime.datetime] = mapped_column( TZDateTime(timezone=True), nullable=True