Issues (90)

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.

src/Register.php (8 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
 * Register Class Doc Comment
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  OpenChat
9
 * @author   Ankit Jain <[email protected]>
10
 * @license  The MIT License (MIT)
11
 * @link     https://github.com/ankitjain28may/openchat
12
 */
13
namespace ChatApp;
14
15
require_once dirname(__DIR__).'/vendor/autoload.php';
16
use ChatApp\Validate;
17
use ChatApp\Session;
18
use Dotenv\Dotenv;
19
use mysqli;
20
$dotenv = new Dotenv(dirname(__DIR__));
21
$dotenv->load();
22
23
/**
24
 * Register the User
25
 *
26
 * @category PHP
27
 * @package  OpenChat
28
 * @author   Ankit Jain <[email protected]>
29
 * @license  The MIT License (MIT)
30
 * @link     https://github.com/ankitjain28may/openchat
31
 */
32
class Register
33
{
34
    /*
35
    |--------------------------------------------------------------------------
36
    | Register Class
37
    |--------------------------------------------------------------------------
38
    |
39
    | Save User Details in DB.
40
    |
41
    */
42
43
    protected $error;
44
    protected $flag;
45
    protected $obValidate;
46
    protected $connect;
47
48
    /**
49
     * Create a new class instance.
50
     *
51
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
52
     */
53
    public function __construct()
54
    {
55
        $this->error = array();
56
        $this->flag = 0;
57
        $this->connect = new mysqli(
58
            getenv('DB_HOST'),
59
            getenv('DB_USER'),
60
            getenv('DB_PASSWORD'),
61
            getenv('DB_NAME')
62
        );
63
        $this->obValidate = new Validate();
64
65
    }
66
67
    /**
68
     * Store Message in Db so as to send message to other members
69
     *
70
     * @param object $data To store user details
71
     *
72
     * @return string
73
     */
74
    public function authRegister($data)
75
    {
76
        $data = $this->emptyValue($data);
0 ignored issues
show
$data is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
77
        $name = $data["name"];
78
        $email = $data["email"];
79
        $username = $data["username"];
80
        $mob = $data["mob"];
81
        $password = $data["passRegister"];
82
        $userId = '';
0 ignored issues
show
$userId is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
83
84
        if (filter_var($email, FILTER_VALIDATE_EMAIL) == false) {
85
            $this->onError("email", " *Enter correct Email address");
86
        } else if ($this->obValidate->validateEmailInDb($email) === 1) {
87
            $this->onError("email", " *Email is already registered");
88
        }
89
90
        if ($this->obValidate->validateUsernameInDb($username) === 1) {
91
            $this->onError("username", " *Username is already registered");
92
        }
93
94
        if (!preg_match("/^[0-9]{10}$/", $data["mob"])) {
95
            $this->onError("mob", " *Enter correct Mobile Number");
96
        }
97
98
        if ($this->flag == 1) {
99
            return json_encode($this->error);
100
        }
101
102
        $password = md5($password);
103
104
        $query = "INSERT INTO register VALUES(
105
            null, '$email', '$username', '$password'
106
        )";
107 View Code Duplication
        if (!$this->connect->query($query)) {
0 ignored issues
show
This code seems to be duplicated across 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...
108
            return json_encode(
109
                [
110
                "Error" => "You are not registered, ".$this->connect->error
111
                ]
112
            );
113
        }
114
        $query = "SELECT id FROM register WHERE email = '$email'";
115
        if ($result = $this->connect->query($query)) {
116
            $row = $result->fetch_assoc();
117
            $userId = $row['id'];
118
            $query = "INSERT INTO login VALUES(
119
                '$userId', '$name', '$email', '$username', '$mob', 0
120
            )";
121
122 View Code Duplication
            if (!$this->connect->query($query)) {
0 ignored issues
show
This code seems to be duplicated across 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...
123
                return json_encode(
124
                    [
125
                    "Error" => "You are not registered, ".$this->connect->error
126
                    ]
127
                );
128
            }
129
130
            $query = "INSERT INTO profile VALUES(
131
                '$userId', 'Joined OpenChat', 'Joined OpenChat', ''
132
            )";
133 View Code Duplication
            if (!$this->connect->query($query)) {
0 ignored issues
show
This code seems to be duplicated across 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...
134
                return json_encode(
135
                    [
136
                    "Error" => "You are not registered, ".$this->connect->error
137
                    ]
138
                );
139
            }
140
141
            Session::put('start', $userId);
142
            return json_encode(
143
                [
144
                "location" => getenv('APP_URL')."/views/account.php"
145
                ]
146
            );
147
        }
148
    }
149
150
151
    /**
152
     * For Adding Error statements
153
     *
154
     * @param string $key   To store Key
155
     * @param string $value To store Key
156
     *
157
     * @return void
158
     */
159 View Code Duplication
    public function onError($key, $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...
160
    {
161
        $this->flag = 1;
162
        $this->error = array_merge(
163
            $this->error,
164
            [["key" => $key, "value" => $value]]
165
        );
166
    }
167
168
    /**
169
     * For Traversing data to check for error
170
     *
171
     * @param array $data To store Data
172
     *
173
     * @return array
174
     */
175
    public function emptyValue($data)
176
    {
177
        $errorCode = array(
178
            "name" => " *Enter the name",
179
            "email" => " *Enter the email address",
180
            "username" => " *Enter the username",
181
            "passRegister" => " *Enter the password",
182
            "mob" => " *Enter the Mobile Number"
183
        );
184
185 View Code Duplication
        foreach ($data as $key => $value) {
0 ignored issues
show
This code seems to be duplicated across 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...
186
            $data[$key] = trim($data[$key]);
187
            $value = trim($value);
188
            if (empty($value)) {
189
                $this->onError($key, $errorCode[$key]);
190
            }
191
        }
192
        return $data;
193
    }
194
}
195