From a0747ad62f89d5e1b210d904762a1e61b0513328 Mon Sep 17 00:00:00 2001 From: David Hoppenbrouwers Date: Sat, 15 Oct 2022 19:49:58 +0200 Subject: [PATCH] Forbid any whitespace in usernames This should prevent confusion between e.g. 'A B' and 'A B' --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 3156679..3cd16ad 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ from db.sqlite import DB import os, sys, subprocess import passlib.hash, secrets import time +import string from datetime import datetime import captcha, password, minimd @@ -357,9 +358,9 @@ def edit_comment(comment_id): def register(): if request.method == 'POST': username, passwd = request.form['username'], request.form['password'] - if username != username.strip(): + if any(c in username for c in string.whitespace): # This error is more ergonomic in case someone tries to play tricks again :) - flash('Username may not begin or end with whitespace', 'error') + flash('Username may not contain whitespace', 'error') elif len(username) < 3: flash('Username must be at least 3 characters long', 'error') elif len(passwd) < 8: