]>
git.bts.cx Git - cx.git/blob - cx/lib/users.php
3 cx_require('lib', 'db.php');
4 cx_require('lib', 'setup.php');
6 function cx_users_find_user($id = null, $name = null, $password_hash = null) {
14 foreach (cx_db_query($sql, $id) as $user) {
15 return $user['user_id'];
17 } else if ($name != null && $password_hash != null) {
22 AND user_password_hash == ?
25 foreach (cx_db_query($sql, $name, $password_hash) as $user) {
26 return $user['user_id'];
33 function cx_users_hash_password_for_user($username, $password) {
41 foreach (cx_db_query($sql, $username) as $user) {
42 $salt = $user['user_salt'];
45 $password_hash = sha1($salt . $password);
46 return $password_hash;
49 function cx_users_add_user($name, $password) {
50 $creation_time = time();//
51 $salt = sha1(random_bytes(100));
52 $password_hash = sha1($salt . $password);
54 $sql = 'INSERT INTO users (
60 VALUES (?, ?, ?, ?);';
61 $user_id = cx_db_exec($sql, $creation_time, $name, $salt, $password_hash);
65 cx_setup_register(1, function() {
66 cx_db_exec('CREATE TABLE users (
67 user_id INTEGER PRIMARY KEY,
68 user_creation_time INTEGER,
71 user_password_hash STRING