Issues (3099)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Constraints/PasswordRestrictionsValidator.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminBundle\Validator\Constraints;
4
5
use Symfony\Component\Validator\Constraint;
6
use Symfony\Component\Validator\ConstraintValidator;
7
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
8
9
/**
10
 * Class PasswordRestrictionsValidator
11
 */
12
class PasswordRestrictionsValidator extends ConstraintValidator
13
{
14
    /**
15
     * @var int
16
     */
17
    private $minDigits;
18
19
    /**
20
     * @var int
21
     */
22
    private $minUppercase;
23
24
    /**
25
     * @var int
26
     */
27
    private $minSpecialCharacters;
28
29
    /**
30
     * @var int
31
     */
32
    private $minLength;
33
34
    /**
35
     * @var int
36
     */
37
    private $maxLength;
38
39
    /**
40
     * PasswordRestrictionsValidator constructor.
41
     *
42
     * @param int $minDigits
43
     * @param int $minUpperCase
44
     * @param int $minSpecialCharacters
45
     * @param int $minLength
46
     * @param int $maxLength
47
     */
48 20
    public function __construct($minDigits, $minUpperCase, $minSpecialCharacters, $minLength, $maxLength)
49
    {
50 20
        $this->minDigits = $minDigits;
51 20
        $this->minUppercase = $minUpperCase;
52 20
        $this->minSpecialCharacters = $minSpecialCharacters;
53 20
        $this->minLength = $minLength;
54 20
        $this->maxLength = $maxLength;
55 20
    }
56
57
    /**
58
     * Checks if the passed value is valid.
59
     *
60
     * @param string     $value      The value that should be validated
61
     * @param Constraint $constraint The constraint for the validation
62
     */
63 20
    public function validate($value, Constraint $constraint)
64
    {
65 20
        if (!$constraint instanceof PasswordRestrictions) {
66
            throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\PasswordRestrictions');
67
        }
68
69 20
        if (null === $value) {
70
            return;
71
        }
72
73 20
        if (null !== $this->minLength) {
74 12
            $this->validateMinLength($value);
75
        }
76
77 20
        if (null !== $this->maxLength) {
78 11
            $this->validateMaxLength($value);
79
        }
80
81 20
        if (null !== $this->minDigits) {
82 8
            $this->validateMinDigits($value);
83
        }
84
85 20
        if (null !== $this->minUppercase) {
86 8
            $this->validateMinUppercase($value);
87
        }
88
89 20
        if (null !== $this->minSpecialCharacters) {
90 8
            $this->validateMinSpecialCharacters($value);
91
        }
92 20
    }
93
94
    /**
95
     * @param string $value
96
     */
97 12 View Code Duplication
    private function validateMinLength($value)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99 12
        if (\strlen($value) < $this->minLength) {
100 4
            $this->context->buildViolation(PasswordRestrictions::MESSAGE_MIN_LENGTH)
101 4
                ->setParameter('{{ min_length }}', $this->minLength)
102 4
                ->setCode(PasswordRestrictions::INVALID_MIN_LENGTH_ERROR)
103 4
                ->addViolation();
104
        }
105 12
    }
106
107
    /**
108
     * @param string $value
109
     */
110 11 View Code Duplication
    private function validateMaxLength($value)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
    {
112 11
        if (\strlen($value) > $this->maxLength) {
113 3
            $this->context->buildViolation(PasswordRestrictions::MESSAGE_MAX_LENGTH)
114 3
                ->setParameter('{{ max_length }}', $this->maxLength)
115 3
                ->setCode(PasswordRestrictions::INVALID_MAX_LENGTH_ERROR)
116 3
                ->addViolation();
117
        }
118 11
    }
119
120
    /**
121
     * @param string $value
122
     */
123 8 View Code Duplication
    private function validateMinDigits($value)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
    {
125 8
        if (preg_match_all('/\d/', $value) < $this->minDigits) {
126 2
            $this->context->buildViolation(PasswordRestrictions::MESSAGE_MIN_DIGITS)
127 2
                ->setParameter('{{ min_digits }}', $this->minDigits)
128 2
                ->setCode(PasswordRestrictions::INVALID_MIN_DIGITS_ERROR)
129 2
                ->addViolation();
130
        }
131 8
    }
132
133
    /**
134
     * @param string $value
135
     */
136 8 View Code Duplication
    private function validateMinUppercase($value)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
    {
138 8
        if (preg_match_all('/[A-Z]/', $value) < $this->minUppercase) {
139 2
            $this->context->buildViolation(PasswordRestrictions::MESSAGE_MIN_UPPERCASE)
140 2
                ->setParameter('{{ min_uppercase }}', $this->minUppercase)
141 2
                ->setCode(PasswordRestrictions::INVALID_MIN_UPPERCASE_ERROR)
142 2
                ->addViolation();
143
        }
144 8
    }
145
146
    /**
147
     * @param string $value
148
     */
149 8 View Code Duplication
    private function validateMinSpecialCharacters($value)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
    {
151 8
        if (preg_match_all('/[^a-zA-Z0-9]/', $value) < $this->minSpecialCharacters) {
152 2
            $this->context->buildViolation(PasswordRestrictions::MESSAGE_MIN_SPECIAL_CHARACTERS)
153 2
                ->setParameter('{{ min_special_characters }}', $this->minSpecialCharacters)
154 2
                ->setCode(PasswordRestrictions::INVALID_MIN_SPECIAL_CHARACTERS_ERROR)
155 2
                ->addViolation();
156
        }
157 8
    }
158
}
159