From 4dc62bcb259acf1f8a586c0ecb9c4901260f901c Mon Sep 17 00:00:00 2001 From: Lyanis Souidi Date: Mon, 31 Aug 2026 16:57:49 +0200 Subject: [PATCH] Ajout contraintes --- app/__init__.py | 12 +++++++++--- app/templates/pages/password_reset_form.html.j2 | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 5b6eb77..cc225a0 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,6 +1,6 @@ from datetime import datetime from flask import Flask, Blueprint, flash, render_template, request, url_for -import ldap, ldap.filter, os +import ldap, ldap.filter, os, re from app.exceptions import LoginNotFoundException, MultipleUsersFoundForLoginException from flask_migrate import Migrate from flask_mail import Mail, Message @@ -11,6 +11,10 @@ load_dotenv() f_app = Flask(__name__) f_app.secret_key = os.getenv("SECRET_KEY") +PASSWORD_PATTERN = re.compile( + r"""[A-Za-z0-9@#$%^&*\-_=+\[\]{}|\\:',.?/`~"();<> ]{5,255}""" +) + bp = Blueprint('mdp', __name__) f_app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("DATABASE_URI") @@ -114,7 +118,9 @@ def password_reset_form(token: str = None): if not newpassword: error = "Le champ 'mot de passe' ne peut pas être vide." - + elif not PASSWORD_PATTERN.fullmatch(newpassword): + error = "Le mot de passe ne respecte pas les contraintes." + if error is not None: flash(error) return render_template('pages/password_reset_form.html.j2') @@ -193,4 +199,4 @@ def ldap_set_password(user_dn: str, newpassword: str): conn.modify_s(user_dn, [(ldap.MOD_REPLACE, 'unicodePwd', ['"{0}"'.format(newpassword).encode('utf-16-le')])]) -f_app.register_blueprint(bp) \ No newline at end of file +f_app.register_blueprint(bp) diff --git a/app/templates/pages/password_reset_form.html.j2 b/app/templates/pages/password_reset_form.html.j2 index 9eaf8e1..0ecfd34 100644 --- a/app/templates/pages/password_reset_form.html.j2 +++ b/app/templates/pages/password_reset_form.html.j2 @@ -5,13 +5,23 @@ {% block content %}

Définissez votre nouveau mot de passe

+

+ Taille minimum : 5 caractères
+ Taille maximum : 255 caractères
+ Caractères autorisés :
+   • A-Z
+   • a-z
+   • 0-9
+   • @ # $ % ^ & * - _ ! + = [ ] { } | \ : ' , . ? / ` ~ " ( ) ; < >
+   • Espace +

- +
-{% endblock %} \ No newline at end of file +{% endblock %}