mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge Profile validator into regular validator
This commit is contained in:
parent
85d3c7df34
commit
2b00e072d8
1 changed files with 11 additions and 16 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue