def __call__(self, value):
     if not settings.PASSWORD_USE_CRACKLIB:
         return
     try:
         import crack
     except ImportError:
         return
     crack.diff_ok = self.diff_ok
     crack.dig_credit = self.dig_credit
     crack.low_credit = self.low_credit
     crack.min_length = self.min_length
     crack.oth_credit = self.oth_credit
     crack.up_credit = self.up_credit
     try:
         crack.FascistCheck(value)
     except ValueError as reason:
         reason = _(str(reason))
         message = _("Please choose a different password, %s." % reason)
         raise ValidationError(message, code=self.code)
Exemplo n.º 2
0
 def validate(self, password, user=None):
     django_lang = get_language()
     new_lang = DJANGO_LANGUAGE_TO_LOCALE.get(django_lang, 'C.UTF-8')
     # print("language for query is", django_lang, ":"
     #       "Locale set to", new_lang)
     oldlang = os.getenv('LANG')
     try:
         os.putenv('LANG', new_lang)
         crack.FascistCheck(password)
     except ValueError as err:
         raise ValidationError(
             _("Cracklib rejected that password: {}").format(err),
             code='cracklib',
         )
     finally:
         if oldlang is None:
             os.unsetenv('LANG')
         else:
             os.putenv('LANG', oldlang)