summaryrefslogtreecommitdiff
path: root/htdocs/moderate/src/accounts.inc.php
blob: fac6c7c99e0dca0f6060414ba7ccf01758f89bf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/* $Id: accounts.inc.php 134 2011-03-08 23:35:57Z jessemorgan $ */

function getAccount($id) {
    $query = "SELECT * FROM jpm_users WHERE"
        . "`id`='$id' OR `email`='$id'";
    
    $db = getDatabase();

    $results = array();

    try {
        $results = $db->fetchAssocRow($query);

    } catch (Cif_Database_Exception $e) {
        $results = false;
    }

    return $results;
}

function updatePassword($id, $password) {
    $db = getDatabase();

    $row['password'] = sha1($password);
    
    $db->update('jpm_users', $row, "WHERE `id`='$id'");
}

function getAccounts($s) {
    $query = "SELECT * FROM jpm_users";
    
    if (!is_null($s)) {
        $s = addslashes($s);
        $query .= " WHERE name LIKE '%$s%' OR email LIKE '%$s%'";
    }

    $query .= " ORDER BY name";
    
    $db = getDatabase();

    $results = array();

    try {
        $results = $db->fetchAssocRows($query);

    } catch (Cif_Database_Exception $e) {
        $results = array();
    }

    return $results;
}

function generatePassword() {
    $alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz123456789!@#$%*()";
    $length = strlen($alphabet);

    $password = '';
    for ($i = 0; $i < 8; $i++) {
        $pos = rand(0, $length - 1);
        $password .= substr($alphabet, $pos, 1); 
    }

    return $password;
}

?>