1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-22 09:24:21 +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
class PPolicy:
def __init__(self, config, logger):
""" password policy constructor
@dict config: the configuration of the ppolicy
@logger logger: a python logger
"""
pass
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'}
def info(self):
""" gives information about the ppolicy
@rtype: a string describing the ppolicy
"""
ret = "There is no password policy configured"
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:
return self.config[param]
elif not default is None:
elif default is not None:
return default
else:
raise MissingParameter('ppolicy', param)
raise MissingParameter('ppolicy', param)

View File

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