User::verifyPassword()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
namespace Forum\User;
3
4
use Forum\Gravatar\CurlService;
5
use Anax\DatabaseActiveRecord\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
     * Columns in the table.
19
     *
20
     * @var integer $id primary key auto incremented.
21
     */
22
    public $id;
23
    public $acronym;
24
    public $password;
25
    public $email;
26
    public $created;
27
    public $updated;
28
    public $deleted;
29
    public $active;
30
31
    /**
32
     * Set the password.
33
     *
34
     * @param string $password the password to use.
35
     *
36
     * @return void
37
     */
38
    public function setPassword($password)
39
    {
40
        $this->password = password_hash($password, PASSWORD_DEFAULT);
41
    }
42
43
    /**
44
     * Verify the acronym and the password, if successful the object contains
45
     * all details from the database row.
46
     *
47
     * @param string $acronym  acronym to check.
48
     * @param string $password the password to use.
49
     *
50
     * @return boolean true if acronym and password matches, else false.
51
     */
52
    public function verifyPassword($acronym, $password)
53
    {
54
        $this->find("acronym", $acronym);
55
        return password_verify($password, $this->password);
56
    }
57
58
    public function getGravatar()
59
    {
60
        $size = 40;
61
        return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($this->email))) . "?d=identicon" . "&s=" . $size;
62
    }
63
}
64