mirror of
https://github.com/vrana/adminer.git
synced 2025-08-09 16:17:48 +02:00
Permanent login
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1281 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
@@ -3,8 +3,15 @@ if (isset($_POST["server"])) {
|
||||
session_regenerate_id(); // defense against session fixation
|
||||
$_SESSION["usernames"][$_POST["server"]] = $_POST["username"];
|
||||
$_SESSION["passwords"][$_POST["server"]] = $_POST["password"];
|
||||
if (count($_POST) == 3) { // 3 - count($ignore)
|
||||
$location = ((string) $_GET["server"] === $_POST["server"] ? remove_from_uri(session_name()) : preg_replace('~^([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : ''));
|
||||
if ($_POST["permanent"]) {
|
||||
cookie("adminer_permanent",
|
||||
base64_encode($_POST["server"])
|
||||
. ":" . base64_encode($_POST["username"])
|
||||
. ":" . base64_encode(cipher_password($_POST["password"], pack("H*", sha1(str_pad($_POST["username"], 1) . $adminer->permanentLogin())))) // str_pad - to hide original key
|
||||
);
|
||||
}
|
||||
if (count($_POST) == 3 + ($_POST["permanent"] ? 1 : 0)) { // 3 - server, username, password
|
||||
$location = ((string) $_GET["server"] === $_POST["server"] ? remove_from_uri(session_name()) : preg_replace('~^([^?]*).*~', '\\1', ME) . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : ''));
|
||||
if (SID) {
|
||||
$pos = strpos($location, '?');
|
||||
$location = ($pos ? substr_replace($location, SID . "&", $pos + 1, 0) : "$location?" . SID);
|
||||
@@ -12,7 +19,7 @@ if (isset($_POST["server"])) {
|
||||
redirect($location);
|
||||
}
|
||||
$_GET["server"] = $_POST["server"];
|
||||
} elseif (isset($_POST["logout"])) {
|
||||
} elseif ($_POST["logout"]) {
|
||||
$token = $_SESSION["tokens"][$_GET["server"]];
|
||||
if ($token && $_POST["token"] != $token) {
|
||||
page_header(lang('Logout'), lang('Invalid CSRF token. Send the form again.'));
|
||||
@@ -25,8 +32,42 @@ if (isset($_POST["server"])) {
|
||||
if (!isset($_SESSION["passwords"])) { // don't require login to logout
|
||||
$_SESSION["passwords"] = array();
|
||||
}
|
||||
cookie("adminer_permanent", "");
|
||||
redirect(substr(ME, 0, -1), lang('Logout successful.'));
|
||||
}
|
||||
} elseif ($_COOKIE["adminer_permanent"] && !isset($_SESSION["usernames"][$_GET["server"]])) {
|
||||
list($server, $username, $cipher) = array_map('base64_decode', explode(":", $_COOKIE["adminer_permanent"]));
|
||||
if (!strlen($_GET["server"]) || $server == $_GET["server"]) {
|
||||
session_regenerate_id(); // defense against session fixation
|
||||
$_SESSION["usernames"][$server] = $username;
|
||||
$_SESSION["passwords"][$server] = decipher_password($cipher, pack("H*", sha1(str_pad($username, 1) . $adminer->permanentLogin())));
|
||||
if (!$_POST && $server != $_GET["server"]) {
|
||||
redirect(preg_replace('~^([^?]*).*~', '\\1', ME) . '?server=' . urlencode($server));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Cipher password
|
||||
* @param string plain-text password
|
||||
* @param string binary key, should be longer than $password
|
||||
* @return string binary cipher
|
||||
*/
|
||||
function cipher_password($password, $key) {
|
||||
$password2 = strlen($password) . ":" . str_pad($password, 17);
|
||||
$repeat = ceil(strlen($password2) / strlen($key));
|
||||
return $password2 ^ str_repeat($key, $repeat);
|
||||
}
|
||||
|
||||
/** Decipher password
|
||||
* @param string binary cipher
|
||||
* @param string binary key
|
||||
* @return string plain-text password
|
||||
*/
|
||||
function decipher_password($cipher, $key) {
|
||||
$repeat = ceil(strlen($cipher) / strlen($key));
|
||||
$password2 = $cipher ^ str_repeat($key, $repeat);
|
||||
list($length, $password) = explode(":", $password2, 2);
|
||||
return substr($password, 0, $length);
|
||||
}
|
||||
|
||||
function auth_error($exception = null) {
|
||||
|
Reference in New Issue
Block a user