Issues (4)

Security Analysis    no request data  

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

src/DefaultPasswordHasher.php (1 issue)

Severity
1
<?php
2
3
/**
4
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
5
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE.txt
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
12
 * @link          http://cakephp.org CakePHP(tm) Project
13
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
14
 */
15
16
declare(strict_types=1);
17
18
namespace Phauthentic\PasswordHasher;
19
20
use InvalidArgumentException;
21
use RuntimeException;
22
23
/**
24
 * Abstraction of the php password_hash() function
25
 *
26
 * @link http://php.net/manual/en/function.password-hash.php
27
 */
28
class DefaultPasswordHasher extends AbstractPasswordHasher
29
{
30
31
    /**
32
     * Hashing algo to use. Valid values are those supported by `$algo` argument
33
     * of `password_hash()`. Defaults to `PASSWORD_DEFAULT`
34
     *
35
     * @var int|string
36
     */
37
    protected $hashType = PASSWORD_DEFAULT;
38
39
    /**
40
     * Associative array of options. Check the PHP manual for supported options
41
     * for each hash type. Defaults to empty array.
42
     *
43
     * @var array
44
     */
45
    protected $hashOptions = [];
46
47
    /**
48
     * Set Hash Options
49
     *
50
     * @param array $options Associative array of options. Check the PHP manual for supported options for each hash type. Defaults to empty array.
51
     * @return $this
52
     */
53 2
    public function setHashOptions(array $options): self
54
    {
55 2
        $this->hashOptions = $options;
56
57 2
        return $this;
58
    }
59
60
    /**
61
     * Sets the hash type
62
     *
63
     * @param int|string $type Hashing algo to use. Valid values are those supported by `$algo` argument of `password_hash()`. Defaults to `PASSWORD_DEFAULT`
64
     * @return $this
65
     */
66 2
    public function setHashType($type): self
67
    {
68 2
        if (!is_int($type) && !is_string($type)) {
0 ignored issues
show
The condition is_string($type) is always true.
Loading history...
69
            throw new InvalidArgumentException(sprintf(
70
                'You must pass an integer or string value'
71
            ));
72
        }
73
74 2
        $this->hashType = $type;
75
76 2
        return $this;
77
    }
78
79
    /**
80
     * Generates password hash.
81
     *
82
     * @param string $password Plain text password to hash.
83
     * @return string Password hash or false on failure.
84
     */
85 12
    public function hash(string $password): string
86
    {
87 12
        $hash = password_hash(
88 12
            $this->saltPassword($password),
89 12
            $this->hashType,
90 12
            $this->hashOptions
91
        );
92
93 12
        if ($hash === false) {
94
            throw new RuntimeException('Failed to hash password.');
95
        }
96
97 12
        return $hash;
98
    }
99
100
    /**
101
     * Check hash. Generate hash for user provided password and check against existing hash.
102
     *
103
     * @param string $password Plain text password to hash.
104
     * @param string $hashedPassword Existing hashed password.
105
     * @return bool True if hashes match else false.
106
     */
107 6
    public function check(string $password, string $hashedPassword): bool
108
    {
109 6
        return password_verify(
110 6
            $this->saltPassword($password),
111
            $hashedPassword
112
        );
113
    }
114
115
    /**
116
     * Returns true if the password need to be rehashed, due to the password being
117
     * created with anything else than the passwords generated by this class.
118
     *
119
     * @param string $password The password to verify
120
     * @return bool
121
     */
122 6
    public function needsRehash(string $password): bool
123
    {
124 6
        return password_needs_rehash(
125 6
            $this->saltPassword($password),
126 6
            $this->hashType,
127 6
            $this->hashOptions
128
        );
129
    }
130
}
131