Issues (24)

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.

source/Register.php (1 issue)

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  Registration-Module
9
 * @author   Ankit Jain <[email protected]>
10
 * @license  The MIT License (MIT)
11
 * @link     https://github.com/ankitjain28may/registration-module
12
 */
13
14
namespace AnkitJain\RegistrationModule;
15
use AnkitJain\RegistrationModule\Validate;
16
use AnkitJain\RegistrationModule\Session;
17
require_once dirname(__DIR__) . '/config/database.php';
18
19
/**
20
 * For Register the New User
21
 *
22
 * @category PHP
23
 * @package  Registration-Module
24
 * @author   Ankit Jain <[email protected]>
25
 * @license  The MIT License (MIT)
26
 * @link     https://github.com/ankitjain28may/registration-module
27
 */
28
29
class Register
30
{
31
    /*
32
    |--------------------------------------------------------------------------
33
    | Register Class
34
    |--------------------------------------------------------------------------
35
    |
36
    | For Register the New User.
37
    |
38
    */
39
40
    protected $error;
41
    protected $flag;
42
    protected $obValidate;
43
    protected $connect;
44
45
    /**
46
     * Create a new controller instance.
47
     *
48
     * @return void
49
     */
50
    public function __construct()
51
    {
52
        $this->error = array();
53
        $this->flag = 0;
54
        $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
55
        $this->obValidate = new Validate();
56
    }
57
58
    /**
59
     * Credentials check for allowing new user to Register
60
     *
61
     * @param array $data Contains the User Credentials
62
     *
63
     * @return json
64
     */
65
    public function authRegister($data)
66
    {
67
        $data = $this->emptyValue($data);
68
        $name = $data["name"];
69
        $email = $data["email"];
70
        $username = $data["username"];
71
        $mob = $data["mob"];
72
        $password = $data["passRegister"];
73
        $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...
74
75
        if (filter_var($email, FILTER_VALIDATE_EMAIL) == false) {
76
            $this->onError("email", " *Enter correct Email address");
77
        } elseif ($this->obValidate->validateEmailInDb($email) === 1) {
78
            $this->onError("email", " *Email is already registered");
79
        }
80
81
        if ($this->obValidate->validateUsernameInDb($username) === 1) {
82
            $this->onError("username", " *Username is already registered");
83
        }
84
85
        if (!preg_match("/^[0-9]{10}$/", $data["mob"])) {
86
            $this->onError("mob", " *Enter correct Mobile Number");
87
        }
88
89
        if ($this->flag == 1) {
90
            return json_encode($this->error);
91
        }
92
93
        $password = md5($password);
94
95
        $query = "INSERT INTO register VALUES(
96
        	null, '$email', '$username', '$password'
97
        )";
98 View Code Duplication
        if (!$this->connect->query($query)) {
99
            return json_encode(
100
                [
101
                "Error" => "You are not registered, " . $this->connect->error
102
                ]
103
            );
104
        }
105
        $query = "SELECT id FROM register WHERE email = '$email'";
106
        if ($result = $this->connect->query($query)) {
107
            $row = $result->fetch_assoc();
108
            $userId = $row['id'];
109
            $query = "INSERT INTO login VALUES(
110
            	'$userId', '$name', '$email', '$username', '$mob'
111
            )";
112
113 View Code Duplication
            if (!$this->connect->query($query)) {
114
                return json_encode(
115
                    [
116
                    "Error" => "You are not registered, " . $this->connect->error
117
                    ]
118
                );
119
            }
120
121
            Session::put('start', $userId);
122
            return json_encode(
123
                [
124
                "location" => URL . "/account.php"
125
                ]
126
            );
127
        }
128
    }
129
130
    /**
131
     * For generating Error array by key value pair
132
     *
133
     * @param string $key   Contains key
134
     * @param string $value Contains the Value for the key
135
     *
136
     * @return void
137
     */
138 View Code Duplication
    public function onError($key, $value)
139
    {
140
        $this->flag = 1;
141
        $this->error = array_merge(
142
            $this->error,
143
            [
144
            [
145
            "key" => $key,
146
            "value" => $value
147
            ]
148
            ]
149
        );
150
    }
151
152
    /**
153
     * For checking whether the credentials are empty or not
154
     *
155
     * @param array $data Contains the Credentials
156
     *
157
     * @return array
158
     */
159
    public function emptyValue($data)
160
    {
161
        $errorCode = array(
162
            "name" => " *Enter the name",
163
            "email" => " *Enter the email address",
164
            "username" => " *Enter the username",
165
            "passRegister" => " *Enter the password",
166
            "mob" => " *Enter the Mobile Number"
167
        );
168
169 View Code Duplication
        foreach ($data as $key => $value) {
170
            $data[$key] = trim($data[$key]);
171
            $value = trim($value);
172
            if (empty($value)) {
173
                $this->onError($key, $errorCode[$key]);
174
            }
175
        }
176
        return $data;
177
    }
178
}
179