41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# vim:set expandtab tabstop=4 shiftwidth=4:
|
|
#
|
|
# The MIT License (MIT)
|
|
# LdapCherry
|
|
# Copyright (c) 2014 Carpentier Pierre-Francois
|
|
|
|
import ldapcherry.ppolicy
|
|
import re
|
|
|
|
|
|
class PPolicy(ldapcherry.ppolicy.PPolicy):
|
|
|
|
def __init__(self, config, logger):
|
|
self.config = config
|
|
self.min_length = self.get_param('min_length')
|
|
self.min_upper = self.get_param('min_upper')
|
|
self.min_digit = self.get_param('min_digit')
|
|
|
|
def check(self, password):
|
|
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'
|
|
}
|
|
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)d\n" \
|
|
"* Minimum number of uppercase characters: %(upper)d\n" \
|
|
"* Minimum number of digits: %(digit)d" % {
|
|
'upper': self.min_upper,
|
|
'len': self.min_length,
|
|
'digit': self.min_digit
|
|
}
|