Hi Everybody,

Django currently ships with the following password validators:

UserAttributeSimilarityValidator
MinimumLengthValidator
CommonPasswordValidator
NumericPasswordValidator


However, it is typical nowadays to require uppercase, lowercase, at least a 
numeric character and a non-alphanumeric character, or a symbol. 

Is there any reason, why these not included in Django? I assume most 
serious Django applications use them. A sample implementation:

class HasLowerCaseValidator:
   def __init__(self):
      self.message = "The password must contain at least one lowercase 
character."

   def validate(self, password, user=None):
      if re.search('[a-z]', password) is None:
         raise ValidationError(
            self.message,
            code='missing_lower_case',
            )

   def get_help_text(self):
      return self.message


class HasUpperCaseValidator:
   def __init__(self):
      self.message = "The password must contain at least one uppercase 
character."

   def validate(self, password, user=None):
      if re.search('[A-Z]', password) is None:
         raise ValidationError(
            self.message,
            code='missing_upper_case',
            )

   def get_help_text(self):
      return self.message


class HasNumberValidator:
   def __init__(self):
      self.message = "The password must contain at least one numeric character."

   def validate(self, password, user=None):
      if re.search('[0-9]', password) is None:
         raise ValidationError(
            self.message,
            code='missing_numeric',
            )

   def get_help_text(self):
      return self.message


class HasSymbolValidator:
   def __init__(self):
      self.message = "The password must contain at least one non-alphanumeric 
character (symbol)."

   def validate(self, password, user=None):
      if re.search('[^A-Za-z0-9]', password) is None:
         raise ValidationError(
            self.message,
            code='missing_symbol',
            )

   def get_help_text(self):
      return self.message

Regards,


Mehmet 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/afd6d57c-ce8c-4d72-85d4-867cacc8ba9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to