diff --git a/app/reset.py b/app/reset.py index 482ab04..4d3827d 100644 --- a/app/reset.py +++ b/app/reset.py @@ -20,15 +20,16 @@ class ResetPasswordForm(FlaskForm): # Form username = StringField(label=('Login'), validators=[DataRequired(), - Length(max=64)]) + Length(max=64)], + render_kw={"onkeyup": "validate_username()"}) currentpassword = PasswordField(label=('Current password'), validators=[DataRequired()]) newpassword = PasswordField(label=('New password'), validators=[DataRequired(), - Length(min=minlength, message='Password should be at least %(min)d characters long'), - Regexp("^(?=.*[a-z])", message="Password must have a lowercase character"), - Regexp("^(?=.*[A-Z])", message="Password must have an uppercase character"), - Regexp("^(?=.*\\d)", message="Password must contain a number"), + Length(min=minlength), + Regexp("^(?=.*[a-z])"), + Regexp("^(?=.*[A-Z])"), + Regexp("^(?=.*\\d)"), #Regexp( # "(?=.*[@$!%*#?&])", message="Password must contain a special character" #),], @@ -37,7 +38,7 @@ class ResetPasswordForm(FlaskForm): confirm_password = PasswordField( label=('Confirm Password'), validators=[DataRequired(message='* Required'), - EqualTo('newpassword', message='Both password fields must be equal!')], + EqualTo('newpassword')], render_kw={"onkeyup": f"validate_confirm({minlength})"}) submit = SubmitField(label=('Change my password'), render_kw={"onclick": f"validate_form({minlength})"}) diff --git a/app/ui/static/css/main.css b/app/ui/static/css/main.css index fb91c40..b0faa5f 100644 --- a/app/ui/static/css/main.css +++ b/app/ui/static/css/main.css @@ -51,6 +51,7 @@ a:hover>span { font-size: 32px; } +#username-msg, #confirm-msg, #password-msg { color: #d4d4d4; diff --git a/app/ui/static/js/validate.js b/app/ui/static/js/validate.js index 5ab48b5..8d7feeb 100644 --- a/app/ui/static/js/validate.js +++ b/app/ui/static/js/validate.js @@ -1,7 +1,8 @@ function validate_form(minlength) { + var user = validate_username(); var pass = validate_password(minlength); - return validate_confirm() && pass; + return validate_confirm() && pass && user; } function validate_confirm() { @@ -20,6 +21,22 @@ function validate_confirm() { return true; } +function validate_username() { + var username = document.getElementById("username"); + var forbidden = /[*?!'\^+%\&/()=}{\$#;,\\"]+/; + + if (username.value.length > 64 || forbidden.test(username.value) == true) + { + document.getElementById("username-msg").classList.add("errormsg"); + username.classList.add("errorinput"); + return false; + } + + document.getElementById("username-msg").classList.remove("errormsg"); + username.classList.remove("errorinput"); + return true; +} + function validate_password(minlength) { // Did the checks pass ? var status = true; @@ -56,7 +73,9 @@ function validate_password(minlength) { document.getElementById("upper").classList.remove("errormsg"); // Change the color of the inputbox if (status == false) + { password.classList.add("errorinput"); + } else password.classList.remove("errorinput"); diff --git a/app/ui/templates/reset.html b/app/ui/templates/reset.html index a57e89a..b593e02 100644 --- a/app/ui/templates/reset.html +++ b/app/ui/templates/reset.html @@ -2,13 +2,13 @@ {% block main_block %}
- {% for field, errors in form.errors.items() %} - {{ ', '.join(errors) }} - {% endfor %}
{{ form.csrf_token() }}
{{ form.username.label }} +
+ The username can contain at most 64 characters and cannot contain one of the following characters : [*?!'^+%&/()=}{$#;,\" +
{{ form.username(class="form-control") }}
@@ -36,7 +36,7 @@ {{ form.confirm_password(class="form-control") }}

-
+
{{ form.submit(class="btn btn-primary")}}