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.

src/User/User.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
namespace Oenstrom\User;
4
5
use \Anax\Database\ActiveRecordModel;
6
7
/**
8
 * A database driven model.
9
 */
10
class User extends ActiveRecordModel
11
{
12
    /**
13
     * @var string $tableName name of the database table.
14
     */
15
    protected $tableName = "User";
16
17
18
19
    /**
20
     * Columns in the table.
21
     *
22
     * @var integer $id primary key auto incremented.
23
     * @var string $role not null default "user".
24
     * @var string $username unique not null.
25
     * @var string $password not null.
26
     * @var string $email unique not null.
27
     * @var timestamp $created default CURRENT_TIMESTAMP.
28
     * @var timestamp $deleted default null.
29
     */
30
    public $id;
31
    public $role;
32
    public $username;
33
    public $password;
34
    public $email;
35
    public $created;
36
    //public $updated;
37
    public $deleted;
38
    //public $active;
39
40
41
42
    /**
43
     * Set the name of the user table.
44
     *
45
     * @param string $tableName the name of the user table
46
     */
47 20
    public function __construct($tableName = "User")
48
    {
49 20
        $this->tableName = $tableName;
50 20
    }
51
52
53
54
    /**
55
     * Set the user password.
56
     *
57
     * @param string $password the password to hash.
58
     *
59
     * @return void
60
     */
61 1
    public function setPassword($password)
62
    {
63 1
        $this->password = password_hash($password, PASSWORD_DEFAULT);
64 1
    }
65
66
67
68
    /**
69
     * Check if password is correct.
70
     *
71
     * @param string $username the username of the user
72
     * @param string $password the password of the user
73
     *
74
     * @return boolean true if the password match the user password, else false
75
     */
76 2
    public function verifyPassword($username, $password)
77
    {
78 2
        $this->find("username", $username);
79 2
        return password_verify($password, $this->password);
80
    }
81
82
83
84
    /**
85
     * Check if the username already exists in the database.
86
     *
87
     * @return string|null the username if it exists, else null
88
     */
89 2
    public function usernameExists($username)
90
    {
91 2
        $this->find("username", $username);
92 2
        return $this->username;
93
    }
94
95
96
97
    /**
98
     * Check if the email already exists in the database.
99
     *
100
     * @return string|null the email if it exists, else null
101
     */
102 2
    public function emailExists($email)
103
    {
104 2
        $this->find("email", $email);
105 2
        return $this->email;
106
    }
107
108
109
110
    /**
111
     * Check if the user is an admin.
112
     *
113
     * @return boolean true if user is admin, else false
114
     */
115 1
    public function isAdmin()
116
    {
117 1
        return $this->role === "admin";
118
    }
119
120
121
122
    /**
123
     * Get either a Gravatar URL or complete image tag for the user email.
124
     *
125
     * @param boole $img True to return a complete IMG tag False for just the URL
126
     * @param string $size Size in pixels, defaults to 80px [ 1 - 2048 ]
127
     * @param string $default Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
128
     * @param string $rating Maximum rating (inclusive) [ g | pg | r | x ]
129
     * @param array $atts Optional, additional key/value attributes to include in the IMG tag
130
     * @return String containing either just a URL or a complete image tag
131
     * @source https://gravatar.com/site/implement/images/php/
132
     */
133 1
    public function getGravatar($img = false, $size = 80, $default = 'mm', $rating = 'g', $atts = array())
134
    {
135 1
        $url = 'https://www.gravatar.com/avatar/';
136 1
        $url .= md5(strtolower(trim($this->email)));
137 1
        $url .= "?s=$size&d=$default&r=$rating";
138 1 View Code Duplication
        if ($img) {
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...
139 1
            $url = '<img src="' . $url . '" alt="' . $this->email . '"';
140 1
            foreach ($atts as $key => $val) {
141 1
                $url .= ' ' . $key . '="' . $val . '"';
142 1
            }
143 1
            $url .= ' />';
144 1
        }
145 1
        return $url;
146
    }
147
}
148