Passed
Push — dev ( c9c6ca...a0f434 )
by Greg
03:51
created

User::generateHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * /classes/DomainMOD/User.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2019 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
//@formatter:off
22
namespace DomainMOD;
23
24
class User
25
{
26
    public $deeb;
27
28
    public function __construct()
29
    {
30
        $this->deeb = Database::getInstance();
31
    }
32
33
    public function getAdminId()
34
    {
35
        return $this->deeb->cnxx->query("
36
            SELECT id
37
            FROM users
38
            WHERE username = 'admin'")->fetchColumn();
39
    }
40
41
    public function getUserId($username)
42
    {
43
        $stmt = $this->deeb->cnxx->prepare("
44
            SELECT id
45
            FROM users
46
            WHERE username = :username");
47
        $stmt->bindValue('username', $username, \PDO::PARAM_STR);
48
        $stmt->execute();
49
        return $stmt->fetchColumn();
50
    }
51
52
    public function getFullName($user_id)
53
    {
54
        $stmt = $this->deeb->cnxx->prepare("
55
            SELECT first_name, last_name
56
            FROM users
57
            WHERE id = :user_id");
58
        $stmt->bindValue('user_id', $user_id, \PDO::PARAM_INT);
59
        $stmt->execute();
60
        $result = $stmt->fetch();
61
        $stmt->closeCursor();
62
        return $result->first_name . ' ' . $result->last_name;
63
    }
64
65
    public function generatePassword($password_length = 72)
66
    {
67
        $character_pool = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
68
        return substr(str_shuffle($character_pool), 0, $password_length);
69
    }
70
71
    public function generateHash($password)
72
    {
73
        return password_hash($password, PASSWORD_DEFAULT);
74
    }
75
76
} //@formatter:on
77