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.
This commit is contained in:
Harvey Tindall 2020-04-16 14:33:23 +01:00
parent e6eda227fa
commit 4df78a22c5
5 changed files with 23 additions and 12 deletions

View File

@ -112,6 +112,8 @@ enabled = true
min_length = 8 min_length = 8
; Min. number of uppercase characters ; Min. number of uppercase characters
upper = 1 upper = 1
; Min. number of lowercase characters
lower = 0
; Min. number of numbers ; Min. number of numbers
number = 1 number = 1
; Min. number of special characters ; Min. number of special characters

View File

@ -31,6 +31,8 @@ enabled = true
min_length = 8 min_length = 8
; Min. number of uppercase characters ; Min. number of uppercase characters
upper = 1 upper = 1
; Min. number of lowercase characters
lower = 0
; Min. number of numbers ; Min. number of numbers
number = 1 number = 1
; Min. number of special characters ; Min. number of special characters

View File

@ -141,16 +141,18 @@
for (var key in data) { for (var key in data) {
if (data.hasOwnProperty(key)) { if (data.hasOwnProperty(key)) {
var criterion = document.getElementById(key); var criterion = document.getElementById(key);
if (data[key] == false) { if (criterion) {
valid = false; if (data[key] == false) {
if (criterion.classList.contains('list-group-item-success')) { valid = false;
criterion.classList.remove('list-group-item-success'); if (criterion.classList.contains('list-group-item-success')) {
criterion.classList.add('list-group-item-danger'); criterion.classList.remove('list-group-item-success');
}; criterion.classList.add('list-group-item-danger');
} else { };
if (criterion.classList.contains('list-group-item-danger')) { } else {
criterion.classList.remove('list-group-item-danger'); if (criterion.classList.contains('list-group-item-danger')) {
criterion.classList.add('list-group-item-success'); criterion.classList.remove('list-group-item-danger');
criterion.classList.add('list-group-item-success');
};
}; };
}; };
}; };

View File

@ -2,20 +2,24 @@ specials = ['[', '@', '_', '!', '#', '$', '%', '^', '&', '*', '(', ')',
'<', '>', '?', '/', '\\', '|', '}', '{', '~', ':', ']'] '<', '>', '?', '/', '\\', '|', '}', '{', '~', ':', ']']
class PasswordValidator: 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), self.criteria = {'characters': int(min_length),
'uppercase characters': int(upper), 'uppercase characters': int(upper),
'lowercase characters': int(lower),
'numbers': int(number), 'numbers': int(number),
'special characters': int(special)} 'special characters': int(special)}
def validate(self, password): def validate(self, password):
count = {'characters': 0, count = {'characters': 0,
'uppercase characters': 0, 'uppercase characters': 0,
'lowercase characters': 0,
'numbers': 0, 'numbers': 0,
'special characters': 0} 'special characters': 0}
for c in password: for c in password:
count['characters'] += 1 count['characters'] += 1
if c.isupper(): if c.isupper():
count['uppercase characters'] += 1 count['uppercase characters'] += 1
elif c.islower():
count['lowercase characters'] += 1
elif c.isnumeric(): elif c.isnumeric():
count['numbers'] += 1 count['numbers'] += 1
elif c in specials: elif c in specials:

View File

@ -69,10 +69,11 @@ while attempts != 3:
if config.getboolean('password_validation', 'enabled'): if config.getboolean('password_validation', 'enabled'):
validator = PasswordValidator(config['password_validation']['min_length'], validator = PasswordValidator(config['password_validation']['min_length'],
config['password_validation']['upper'], config['password_validation']['upper'],
config['password_validation']['lower'],
config['password_validation']['number'], config['password_validation']['number'],
config['password_validation']['special']) config['password_validation']['special'])
else: else:
validator = PasswordValidator(0, 0, 0, 0) validator = PasswordValidator(0, 0, 0, 0, 0)
@app.route('/getRequirements', methods=['GET', 'POST']) @app.route('/getRequirements', methods=['GET', 'POST'])