1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-29 12:44:31 +01:00

pep 8 on ppolicy + docstrings

This commit is contained in:
kakwa 2015-07-10 21:01:39 +02:00
parent b831bc82dc
commit 2d12335030
2 changed files with 34 additions and 10 deletions

View File

@ -7,21 +7,41 @@
from ldapcherry.exceptions import MissingParameter from ldapcherry.exceptions import MissingParameter
class PPolicy: class PPolicy:
def __init__(self, config, logger): def __init__(self, config, logger):
""" password policy constructor
@dict config: the configuration of the ppolicy
@logger logger: a python logger
"""
pass pass
def check(self, password): def check(self, password):
""" check that a password match the ppolicy
@str password: the password to check
@rtype: dict with keys 'match' a boolean
(True if ppolicy matches, False otherwise)
and 'reason', an explaination string
"""
ret = {'match': True, 'reason': 'no password policy'} ret = {'match': True, 'reason': 'no password policy'}
def info(self): def info(self):
""" gives information about the ppolicy
@rtype: a string describing the ppolicy
"""
ret = "There is no password policy configured" ret = "There is no password policy configured"
def get_param(self, param, default=None): def get_param(self, param, default=None):
"""
@str param: name of the paramter to recover
default: the default value, raises an exception
if param is not in configuration and default
is None (which is the default value).
"""
if param in self.config: if param in self.config:
return self.config[param] return self.config[param]
elif not default is None: elif default is not None:
return default return default
else: else:
raise MissingParameter('ppolicy', param) raise MissingParameter('ppolicy', param)

View File

@ -8,6 +8,7 @@
import ldapcherry.ppolicy import ldapcherry.ppolicy
import re import re
class PPolicy(ldapcherry.ppolicy.PPolicy): class PPolicy(ldapcherry.ppolicy.PPolicy):
def __init__(self, config, logger): def __init__(self, config, logger):
@ -20,17 +21,20 @@ class PPolicy(ldapcherry.ppolicy.PPolicy):
if len(password) < self.min_length: if len(password) < self.min_length:
return {'match': False, 'reason': 'password too short'} return {'match': False, 'reason': 'password too short'}
if len(re.findall(r'[A-Z]', password)) < self.min_upper: if len(re.findall(r'[A-Z]', password)) < self.min_upper:
return {'match': False, 'reason': 'not enough upper case characters'} return {
'match': False,
'reason': 'not enough upper case characters'
}
if len(re.findall(r'[0-9]', password)) < self.min_digit: if len(re.findall(r'[0-9]', password)) < self.min_digit:
return {'match': False, 'reason': 'not enough digits'} return {'match': False, 'reason': 'not enough digits'}
return {'match': True, 'reason': 'password ok'} return {'match': True, 'reason': 'password ok'}
def info(self): def info(self):
return \ return \
"* Minimum length: %(len)n\n\ "* Minimum length: %(len)n\n"\
* Minimum number of uppercase characters: %(upper)n\n\ "* Minimum number of uppercase characters: %(upper)n\n"\
* Minimum number of digits: %(digit)n" % { 'upper': self.min_upper, "* Minimum number of digits: %(digit)n" % {
'upper': self.min_upper,
'len': self.min_length, 'len': self.min_length,
'digit': self.min_digit, 'digit': self.min_digit
} }