librenms-librenms/html/includes/authenticate.inc
Adam Amstrong 96cc0308fd security fixes and some juniper graphing stuff.
git-svn-id: http://www.observium.org/svn/observer/trunk@245 61d68cd4-352d-0410-923a-c4978735b2b8
2008-07-22 08:24:34 +00:00

39 lines
1.1 KiB
PHP

<?php
if($_GET['logout']) {
session_start();
session_destroy();
header('Location: /');
setcookie ("username", "", time() - 3600);
setcookie ("encrypted", "", time() - 3600);
echo("$_COOKIE[username]");
} else {
session_start();
if($_POST['username'] && $_POST['password']){
$_SESSION['username']=$_POST['username'];
$_SESSION['password']=$_POST['password'];
$_SESSION['encrypted'] = md5($_SESSION['password']);
} elseif($_COOKIE['username'] && $_COOKIE['encrypted'] && !$_SESSION['authenticated']) {
$_SESSION['username']=$_COOKIE['username'];
$_SESSION['encrypted']=$_COOKIE['encrypted'];
}
$sql = "select username, level, user_id from users where username='" . mres($_SESSION['username']) . "' and password='" . mres($_SESSION['encrypted']) . "'";
$query = mysql_query($sql);
$row = mysql_fetch_row($query);
if ( $_SESSION['username'] != "" && $row[0] == $_SESSION['username'] ) {
$_SESSION['userlevel'] = $row[1];
$_SESSION['authenticated'] = true;
$_SESSION['user_id'] = $row[2];
setcookie("username", $username);
setcookie("encrypted", $encrypted);
}
}
?>