Issues (15)

Security Analysis    no request data  

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.

Model/PasswordManagement.php (3 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
declare(strict_types=1);
3
4
/**
5
 * File:PasswordManagement.php
6
 *
7
 * @author Maciej Sławik <[email protected]>
8
 * @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
9
 */
10
11
namespace LizardMedia\PasswordMigrator\Model;
12
13
use Exception;
14
use LizardMedia\PasswordMigrator\Api\Data\PasswordRepositoryInterface;
15
use LizardMedia\PasswordMigrator\Api\PasswordManagementInterface;
16
use Magento\Customer\Api\AccountManagementInterface;
17
use Magento\Customer\Api\CustomerRepositoryInterface;
18
use Magento\Customer\Model\AccountManagement;
19
use Magento\Customer\Model\CustomerRegistry;
20
use Magento\Framework\Exception\InputException;
21
use Magento\Framework\Exception\LocalizedException;
22
use Magento\Framework\Exception\NoSuchEntityException;
23
24
/**
25
 * Class PasswordManagement
26
 * @package LizardMedia\PasswordMigrator\Model
27
 */
28
class PasswordManagement implements PasswordManagementInterface
29
{
30
    /**
31
     * @var PasswordRepositoryInterface
32
     */
33
    private $passwordRepository;
34
35
    /**
36
     * @var CustomerRepositoryInterface
37
     */
38
    private $customerRepository;
39
40
    /**
41
     * @var AccountManagementInterface
42
     */
43
    private $accountManagement;
44
45
    /**
46
     * @var CustomerRegistry
47
     */
48
    private $customerRegistry;
49
50
    /**
51
     * PasswordManagement constructor.
52
     * @param PasswordRepositoryInterface $passwordRepository
53
     * @param CustomerRepositoryInterface $customerRepository
54
     * @param AccountManagementInterface $accountManagement
55
     * @param CustomerRegistry $customerRegistry
56
     */
57
    public function __construct(
58
        PasswordRepositoryInterface $passwordRepository,
59
        CustomerRepositoryInterface $customerRepository,
60
        AccountManagementInterface $accountManagement,
61
        CustomerRegistry $customerRegistry
62
    ) {
63
        $this->passwordRepository = $passwordRepository;
64
        $this->customerRepository = $customerRepository;
65
        $this->accountManagement = $accountManagement;
66
        $this->customerRegistry = $customerRegistry;
67
    }
68
69
    /**
70
     * @param int $customerId
71
     * @param string $newPassword
72
     * @return void
73
     * @throws InputException
74
     */
75
    public function updateCustomerPassword(int $customerId, string $newPassword): void
76
    {
77
        try {
78
            $this->generateNewResetToken($customerId);
79
            $this->updatePassword($customerId, $newPassword);
80
            $this->removeLegacyPassword($customerId);
81
        } catch (InputException $exception) {
0 ignored issues
show
The class Magento\Framework\Exception\InputException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
82
            throw $exception;
83
        } catch (Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by Bartosz Kubicki
Consider adding a comment why this CATCH block is empty.
Loading history...
84
        }
85
    }
86
87
    /**
88
     * @param int $customerId
89
     * @throws LocalizedException
90
     * @throws NoSuchEntityException
91
     */
92
    private function generateNewResetToken(int $customerId): void
93
    {
94
        $customerData = $this->customerRepository->getById($customerId);
95
        try {
96
            $this->accountManagement->initiatePasswordReset($customerData->getEmail(), false);
97
        } catch (Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by Maciej Sławik
Consider adding a comment why this CATCH block is empty.
Loading history...
98
        }
99
    }
100
101
    /**
102
     * @param int $customerId
103
     * @param string $newPassword
104
     * @throws LocalizedException
105
     * @throws NoSuchEntityException
106
     */
107
    private function updatePassword(int $customerId, string $newPassword): void
108
    {
109
        $customer = $this->customerRegistry->retrieve($customerId);
110
        $this->accountManagement->resetPassword(
111
            $customer->getData('email'),
112
            $customer->getData('rp_token'),
113
            $newPassword
114
        );
115
    }
116
117
    /**
118
     * @param int $customerId
119
     * @return void
120
     * @throws NoSuchEntityException
121
     * @throws Exception
122
     */
123
    private function removeLegacyPassword(int $customerId): void
124
    {
125
        $password = $this->passwordRepository->getByCustomerId($customerId);
126
        $this->passwordRepository->delete($password);
127
    }
128
}
129