mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] implement password checks with cracklib to detect too weak passwords
This commit is contained in:
parent
64fc8ed5dd
commit
73760c4a7d
1 changed files with 12 additions and 0 deletions
|
@ -32,12 +32,18 @@ import errno
|
||||||
import subprocess
|
import subprocess
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
|
import cracklib
|
||||||
|
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils.log import getActionLogger
|
||||||
|
|
||||||
logger = getActionLogger('yunohost.user')
|
logger = getActionLogger('yunohost.user')
|
||||||
|
|
||||||
|
def _check_password(password):
|
||||||
|
try:
|
||||||
|
cracklib.VeryFascistCheck(password)
|
||||||
|
except ValueError as e:
|
||||||
|
raise MoulinetteError(errno.EINVAL, m18n.n('password_too_weak') + " : " + str(e) )
|
||||||
|
|
||||||
def user_list(auth, fields=None, filter=None, limit=None, offset=None):
|
def user_list(auth, fields=None, filter=None, limit=None, offset=None):
|
||||||
"""
|
"""
|
||||||
|
@ -110,6 +116,9 @@ def user_create(auth, username, firstname, lastname, mail, password,
|
||||||
from yunohost.hook import hook_callback
|
from yunohost.hook import hook_callback
|
||||||
from yunohost.app import app_ssowatconf
|
from yunohost.app import app_ssowatconf
|
||||||
|
|
||||||
|
# Ensure sufficiently complex password
|
||||||
|
_check_password(password)
|
||||||
|
|
||||||
# Validate uniqueness of username and mail in LDAP
|
# Validate uniqueness of username and mail in LDAP
|
||||||
auth.validate_uniqueness({
|
auth.validate_uniqueness({
|
||||||
'uid' : username,
|
'uid' : username,
|
||||||
|
@ -291,6 +300,9 @@ def user_update(auth, username, firstname=None, lastname=None, mail=None,
|
||||||
new_attr_dict['cn'] = new_attr_dict['displayName'] = firstname + ' ' + lastname
|
new_attr_dict['cn'] = new_attr_dict['displayName'] = firstname + ' ' + lastname
|
||||||
|
|
||||||
if change_password:
|
if change_password:
|
||||||
|
# Ensure sufficiently complex password
|
||||||
|
_check_password(change_password)
|
||||||
|
|
||||||
char_set = string.ascii_uppercase + string.digits
|
char_set = string.ascii_uppercase + string.digits
|
||||||
salt = ''.join(random.sample(char_set,8))
|
salt = ''.join(random.sample(char_set,8))
|
||||||
salt = '$1$' + salt + '$'
|
salt = '$1$' + salt + '$'
|
||||||
|
|
Loading…
Add table
Reference in a new issue