Merge Profile validator into regular validator

This commit is contained in:
Alexandre Aubin 2018-10-25 17:30:55 +00:00
parent 85d3c7df34
commit 2b00e072d8

View file

@ -45,8 +45,15 @@ class PasswordValidator(object):
[12, 1, 1, 1, 1], [12, 1, 1, 1, 1],
] ]
def __init__(self, validation_strength): def __init__(self, profile):
self.validation_strength = validation_strength self.profile = profile
import json
try:
settings = json.load(open('/etc/yunohost/settings.json', "r"))
setting_key = "security.password." + profile + ".strength"
self.validation_strength = int(settings[setting_key])
except Exception as e:
self.validation_strength = 2 if profile == 'admin' else 1
def validate(self, password): def validate(self, password):
""" """
@ -109,19 +116,7 @@ class PasswordValidator(object):
return True return True
class ProfilePasswordValidator(PasswordValidator): class LoggerPasswordValidator(PasswordValidator):
def __init__(self, profile):
self.profile = profile
import json
try:
settings = json.load(open('/etc/yunohost/settings.json', "r"))
self.validation_strength = int(settings["security.password." + profile +
'.strength'])
except Exception as e:
self.validation_strength = 2 if profile == 'admin' else 1
return
class LoggerPasswordValidator(ProfilePasswordValidator):
""" """
PasswordValidator class validate password PasswordValidator class validate password
""" """
@ -153,7 +148,7 @@ if __name__ == '__main__':
#print("usage: password.py PASSWORD") #print("usage: password.py PASSWORD")
else: else:
pwd = sys.argv[1] pwd = sys.argv[1]
status, msg = ProfilePasswordValidator('user').validate(pwd) status, msg = PasswordValidator('user').validate(pwd)
print(msg) print(msg)
sys.exit(0) sys.exit(0)