1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-06-01 16:48:06 +02:00
ldapcherry/ldapcherry/ppolicy/simple.py

37 lines
1.2 KiB
Python
Raw Normal View History

2015-07-01 08:58:23 +02:00
# -*- coding: utf-8 -*-
# vim:set expandtab tabstop=4 shiftwidth=4:
#
# The MIT License (MIT)
# LdapCherry
# Copyright (c) 2014 Carpentier Pierre-Francois
2015-07-01 23:00:42 +02:00
import ldapcherry.ppolicy
import re
class PPolicy(ldapcherry.ppolicy.PPolicy):
def __init__(self, config, logger):
self.config = config
self.min_length = get_param('min_length')
self.min_upper = get_param('min_upper')
self.min_digit = 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)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,
}