User::setPassword()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
namespace Anax\User;
3
4
use Anax\DatabaseActiveRecord\ActiveRecordModel;
5
6
class User extends ActiveRecordModel
7
{
8
    /**
9
    * @var string $tableName name of the database table.
10
    */
11
    protected $tableName = "User";
12
13
    /**
14
    * Columns in the table.
15
    *
16
    * @var integer $id primary key auto incremented.
17
    */
18
    public $id;
19
    public $username;
20
    public $password;
21
    public $created;
22
    public $updated;
23
    public $activity;
24
25
    /**
26
     * A database driven model.
27
     */
28
    /**
29
    * Set the password.
30
    *
31
    * @param string $password the password to use.
32
    *
33
    * @return void
34
    */
35
    public function setPassword($password)
36
    {
37
        $this->password = password_hash($password, PASSWORD_DEFAULT);
38
    }
39
40
    /**
41
    * Verify the acronym and the password, if successful the object contains
42
    * all details from the database row.
43
    *
44
    * @param string $acronym  acronym to check.
45
    * @param string $password the password to use.
46
    *
47
    * @return boolean true if acronym and password matches, else false.
48
    */
49
    public function verifyPassword($username, $password)
50
    {
51
        $this->find("username", $username);
52
        return password_verify($password, $this->password);
53
    }
54
}
55