From b3b47ac0cb97b840ccecf98c476bcf4ad4a451ba Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Wed, 12 Feb 2025 14:17:49 +0100 Subject: [PATCH] views: accept only user credentials without whitespace Check the presence of whitespace for new usernames or passwords. Usernames with whitespace can't be deleted because whitespace is the separator of each element selected in the form. --- ogcp/views.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ogcp/views.py b/ogcp/views.py index 7e7877e..ef64ade 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -3485,6 +3485,14 @@ def user_add_post(): flash(form.errors, category='error') return redirect(url_for('users')) + if re.search(r'\s', form.username.data): + flash(_('The username cannot contain spaces'), category='error') + return redirect(url_for('users')) + + if re.search(r'\s', form.pwd.data): + flash(_('The password cannot contain spaces'), category='error') + return redirect(url_for('users')) + if get_user(form.username.data): flash(_('This username already exists'), category='error') return redirect(url_for('users'))