Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.145.105.85
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/3/task/3/cwd/srv/modoboa/env/lib/python3.5/site-packages/modoboa/core/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/3/task/3/cwd/srv/modoboa/env/lib/python3.5/site-packages/modoboa/core//password_validation.py
"""Custom password validators."""

from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _, ungettext


class ComplexityValidator(object):
    """Check password contains at least a few things."""

    def __init__(self, upper=1, lower=1, digits=1, specials=1):
        self.upper = upper
        self.lower = lower
        self.digits = digits
        self.specials = specials

    def validate(self, password, user=None):
        special_characters = "~!@#$%^&*()_+{}\":;,'[]"
        condition = (
            self.digits > 0 and
            sum(1 for char in password if char.isdigit()) < self.digits)
        if condition:
            raise ValidationError(
                ungettext(
                    "Password must contain at least {} digit.",
                    "Password must contain at least {} digits.",
                    self.digits
                ).format(self.digits))
        condition = (
            self.lower > 0 and
            sum(1 for char in password if char.islower()) < self.lower)
        if condition:
            raise ValidationError(
                ungettext(
                    "Password must contain at least {} lowercase letter.",
                    "Password must contain at least {} lowercase letters.",
                    self.lower
                )
                .format(self.lower))
        condition = (
            self.upper > 0 and
            sum(1 for char in password if char.isupper()) < self.upper)
        if condition:
            raise ValidationError(
                ungettext(
                    "Password must contain at least {} uppercase letter.",
                    "Password must contain at least {} uppercase letters.",
                    self.upper
                )
                .format(self.upper))
        condition = (
            self.specials > 0 and
            sum(1 for char in password if char in special_characters) <
            self.specials)
        if condition:
            raise ValidationError(
                ungettext(
                    "Password must contain at least {} special character.",
                    "Password must contain at least {} special characters.",
                    self.specials
                )
                .format(self.specials))

    def get_help_text(self):
        return _(
            "Your password must contain a combination of different "
            "character types.")

Anon7 - 2022
AnonSec Team