summaryrefslogtreecommitdiff
path: root/src/web/helpers/auth.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/web/helpers/auth.php27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/web/helpers/auth.php b/src/web/helpers/auth.php
index 7aa4aff..3ff1e71 100644
--- a/src/web/helpers/auth.php
+++ b/src/web/helpers/auth.php
@@ -2,6 +2,27 @@
$keys = array();
+function get_cookie() {
+ $cookie_name = 'X-LDAP-Auth-Key';
+ if(isset($_COOKIE[$cookie_name])) {
+ return $_COOKIE[$cookie_name];
+ } else {
+ return FALSE;
+ }
+}
+
+function store_cookie($key) {
+ $cookie_name = 'X-LDAP-Auth-Key';
+ setcookie(
+ $cookie_name,
+ $key,
+ time() + (86400 * 30),
+ "/",
+ TRUE,
+ TRUE
+ );
+}
+
function load_key($key) {
$file = "/tmp/$key";
if (!file_exists($file))
@@ -34,10 +55,10 @@ function get_random($n)
}
function key_auth() {
- if (!isset($_SESSION['auth'])) {
+ $key = get_cookie();
+ if ($key === FALSE) {
return FALSE;
}
- $key = $_SESSION['auth'];
$data = load_key($key);
if ($data === FALSE) {
return FALSE;
@@ -55,5 +76,5 @@ function key_auth() {
function key_new($user) {
$key = get_random(128);
store_key($key, $user);
- $_SESSION['auth'] = $key;
+ store_cookie($key);
}