From 4df78a22c5a2a48cc72d936c4002528ba8ea7d6b Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Thu, 16 Apr 2020 14:33:23 +0100 Subject: [PATCH] Fixed password validation on form; added lowercase option Fixed an issue where some criteria on the form page wouldn't change to red or green when one set one of them to 0 in the config. Also added a lowercase option. --- README.md | 2 ++ data/config-default.ini | 2 ++ data/templates/form.html | 22 ++++++++++++---------- jellyfin_accounts/validate_password.py | 6 +++++- jellyfin_accounts/web_api.py | 3 ++- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 726954b..1213b1c 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,8 @@ enabled = true min_length = 8 ; Min. number of uppercase characters upper = 1 +; Min. number of lowercase characters +lower = 0 ; Min. number of numbers number = 1 ; Min. number of special characters diff --git a/data/config-default.ini b/data/config-default.ini index 59625de..47f0a53 100644 --- a/data/config-default.ini +++ b/data/config-default.ini @@ -31,6 +31,8 @@ enabled = true min_length = 8 ; Min. number of uppercase characters upper = 1 +; Min. number of lowercase characters +lower = 0 ; Min. number of numbers number = 1 ; Min. number of special characters diff --git a/data/templates/form.html b/data/templates/form.html index 784501b..a1d4298 100644 --- a/data/templates/form.html +++ b/data/templates/form.html @@ -141,16 +141,18 @@ for (var key in data) { if (data.hasOwnProperty(key)) { var criterion = document.getElementById(key); - if (data[key] == false) { - valid = false; - if (criterion.classList.contains('list-group-item-success')) { - criterion.classList.remove('list-group-item-success'); - criterion.classList.add('list-group-item-danger'); - }; - } else { - if (criterion.classList.contains('list-group-item-danger')) { - criterion.classList.remove('list-group-item-danger'); - criterion.classList.add('list-group-item-success'); + if (criterion) { + if (data[key] == false) { + valid = false; + if (criterion.classList.contains('list-group-item-success')) { + criterion.classList.remove('list-group-item-success'); + criterion.classList.add('list-group-item-danger'); + }; + } else { + if (criterion.classList.contains('list-group-item-danger')) { + criterion.classList.remove('list-group-item-danger'); + criterion.classList.add('list-group-item-success'); + }; }; }; }; diff --git a/jellyfin_accounts/validate_password.py b/jellyfin_accounts/validate_password.py index 953485e..eb166cf 100644 --- a/jellyfin_accounts/validate_password.py +++ b/jellyfin_accounts/validate_password.py @@ -2,20 +2,24 @@ specials = ['[', '@', '_', '!', '#', '$', '%', '^', '&', '*', '(', ')', '<', '>', '?', '/', '\\', '|', '}', '{', '~', ':', ']'] class PasswordValidator: - def __init__(self, min_length, upper, number, special): + def __init__(self, min_length, upper, lower, number, special): self.criteria = {'characters': int(min_length), 'uppercase characters': int(upper), + 'lowercase characters': int(lower), 'numbers': int(number), 'special characters': int(special)} def validate(self, password): count = {'characters': 0, 'uppercase characters': 0, + 'lowercase characters': 0, 'numbers': 0, 'special characters': 0} for c in password: count['characters'] += 1 if c.isupper(): count['uppercase characters'] += 1 + elif c.islower(): + count['lowercase characters'] += 1 elif c.isnumeric(): count['numbers'] += 1 elif c in specials: diff --git a/jellyfin_accounts/web_api.py b/jellyfin_accounts/web_api.py index 2b581a7..1ea249b 100644 --- a/jellyfin_accounts/web_api.py +++ b/jellyfin_accounts/web_api.py @@ -69,10 +69,11 @@ while attempts != 3: if config.getboolean('password_validation', 'enabled'): validator = PasswordValidator(config['password_validation']['min_length'], config['password_validation']['upper'], + config['password_validation']['lower'], config['password_validation']['number'], config['password_validation']['special']) else: - validator = PasswordValidator(0, 0, 0, 0) + validator = PasswordValidator(0, 0, 0, 0, 0) @app.route('/getRequirements', methods=['GET', 'POST'])