]> jfr.im git - z_archive/KronOS.git/blob - dime/core/login.php
fc886539c582c6b67fa51d32136bce90779302a3
[z_archive/KronOS.git] / dime / core / login.php
1 <?php
2 define('WEBOS', TRUE);
3 require_once('common.php');
4
5 if (empty($_POST['user']) || empty($_POST['pass'])) {
6 make_error('Username or password empty.', 1);
7 }
8 $sth = $db->prepare('SELECT uid, displayname FROM users WHERE username = ? AND password = ?');
9 $sth->bind_param('ss', $_POST['user'], sha1(PWSALT.$_POST['pass']));
10 $sth->execute();
11 $sth->bind_result($uid, $dispname);
12 if (!$sth->fetch()) { // no row returned
13 make_error('Username or password incorrect.', 2);
14 }
15
16 // row returned, user/pw good
17 $sth->close();
18 $sth = $db->prepare('INSERT INTO sessions(sid, uid, started, last, active) VALUES (NULL, ?, NOW(), NOW(), 1)');
19 $sth->bind_param('i', $uid);
20 $sth->execute();
21 $sid = $sth->insert_id;
22
23 make_reply('Logged in!', array('uid' => $uid, 'sid' => $sid, 'name' => $dispname));