| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
// Are the username and password entered? |
|---|
| 6 |
|
|---|
| 7 |
if (isset($_POST['username']) && isset($_POST['password']) && $_POST['username'] != "" && $_POST['password'] != "") { |
|---|
| 8 |
|
|---|
| 9 |
$username = addslashes($_POST['username']); |
|---|
| 10 |
$password = addslashes(md5($_POST['password'])); |
|---|
| 11 |
$code = addslashes(md5($username . time())); |
|---|
| 12 |
|
|---|
| 13 |
db_query("update users set code = '$code' where username = '$username' and password = '$password'"); |
|---|
| 14 |
|
|---|
| 15 |
if (db_affected_rows() > 0) { |
|---|
| 16 |
|
|---|
| 17 |
$result = db_query("select ident, username, name, email, icon, icon_quota from users where code = '$code' and username = '$username' and password = '$password' and active = 'yes'"); |
|---|
| 18 |
$result = $result[0]; |
|---|
| 19 |
|
|---|
| 20 |
$_SESSION['userid'] = (int) $result->ident; |
|---|
| 21 |
$_SESSION['usercode'] = $code; |
|---|
| 22 |
$_SESSION['username'] = stripslashes($result->username); |
|---|
| 23 |
$_SESSION['name'] = stripslashes($result->name); |
|---|
| 24 |
$_SESSION['email'] = stripslashes($result->email); |
|---|
| 25 |
$iconid = (int) $result->icon; |
|---|
| 26 |
if ($iconid == -1) { |
|---|
| 27 |
$_SESSION['icon'] = "default.png"; |
|---|
| 28 |
} else { |
|---|
| 29 |
$icon = db_query("select filename from icons where ident = $iconid"); |
|---|
| 30 |
$_SESSION['icon'] = $icon[0]->filename; |
|---|
| 31 |
} |
|---|
| 32 |
$_SESSION['icon_quota'] = (int) $result->icon_quota; |
|---|
| 33 |
|
|---|
| 34 |
$messages[] = "You have been logged on."; |
|---|
| 35 |
|
|---|
| 36 |
define('redirect_url',url . "home.php"); |
|---|
| 37 |
|
|---|
| 38 |
} else { |
|---|
| 39 |
|
|---|
| 40 |
$messages[] = "Unrecognised username or password. Username: $username, Password: $password. The system could not log you on, or you may not have activated your account."; |
|---|
| 41 |
|
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
} else { |
|---|
| 45 |
|
|---|
| 46 |
$messages[] = "Either the username or password were not specified. The system could not log you on."; |
|---|
| 47 |
|
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
?> |
|---|