mirror of
https://github.com/hrfee/jellyfin-accounts.git
synced 2024-11-15 02:40:10 +00:00
Harvey Tindall
690de58e9f
Password validation added, configurable under the [password_validation] section in config.ini. Each criterion is displayed next to the form, in red or green depending on whether the password passes it. form.html now looks different because of it, whether it is enabled or disabled. An error message is now displayed if the user already exists.
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
specials = ['[', '@', '_', '!', '#', '$', '%', '^', '&', '*', '(', ')',
|
|
'<', '>', '?', '/', '\\', '|', '}', '{', '~', ':', ']']
|
|
|
|
class PasswordValidator:
|
|
def __init__(self, min_length, upper, number, special):
|
|
self.criteria = {'characters': int(min_length),
|
|
'uppercase characters': int(upper),
|
|
'numbers': int(number),
|
|
'special characters': int(special)}
|
|
def validate(self, password):
|
|
count = {'characters': 0,
|
|
'uppercase characters': 0,
|
|
'numbers': 0,
|
|
'special characters': 0}
|
|
for c in password:
|
|
count['characters'] += 1
|
|
if c.isupper():
|
|
count['uppercase characters'] += 1
|
|
elif c.isnumeric():
|
|
count['numbers'] += 1
|
|
elif c in specials:
|
|
count['special characters'] += 1
|
|
for criterion in count:
|
|
if count[criterion] < self.criteria[criterion]:
|
|
count[criterion] = False
|
|
else:
|
|
count[criterion] = True
|
|
return count
|
|
def getCriteria(self):
|
|
lines = {}
|
|
for criterion in self.criteria:
|
|
min = self.criteria[criterion]
|
|
if min > 0:
|
|
text = f"Must have at least {min} "
|
|
if min == 1:
|
|
text += criterion[:-1]
|
|
else:
|
|
text += criterion
|
|
lines[criterion] = text
|
|
return lines
|
|
|
|
|
|
|
|
|
|
|