From 377cae6615e466a9d650b3089b9a9463bc817679 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 11 Mar 2007 06:16:00 +0000 Subject: [PATCH] r1437: Adding an authentication module for Drupal, AuthenticationDrupal --- includes/auth/auth_drupal.php | 128 ++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 includes/auth/auth_drupal.php diff --git a/includes/auth/auth_drupal.php b/includes/auth/auth_drupal.php new file mode 100644 index 0000000..816e992 --- /dev/null +++ b/includes/auth/auth_drupal.php @@ -0,0 +1,128 @@ + 'uid', + 'displayname' => 'name', + 'email' => 'mail', + ); + + /** + * The cookie name to use for Drupal. Leaving this NULL will get it from session_name() + */ + var $cookieName = null; + + // ################################################################### + function _setupDatabase() + { + // check and see if we need to call session_name() + $this->cookieName = ($this->cookieName == null ? session_name() : $this->cookieName); + + // connect to the DB + $this->authDb = new DB_MySQL($this->registry); + $this->authDb->connect('DRUPAL_DATABASE_SERVER', 'DATABASE_USER', 'DATABASE_PASSWORD', 'DATABASE_NAME', false); + } + + // ################################################################### + function _fetchCookieUniqueId() + { + if ($sessionId == null) + { + $this->sessionId = $this->registry->in[ $this->cookieName ]; + } + return $this->sessionId; + } + + // ################################################################### + function _fetchCookiePassword() + { + return true; + } + + // ################################################################### + function _fetchUserUsingCookies() + { + $session = $this->authDb->query_first("SELECT * FROM sessions WHERE sid = '" . $this->authDb->escape_string($this->_fetchCookieUniqueId()) . "'"); + if (!$session OR $session['uid'] == 0) + { + return false; + } + return $this->authDb->query_first("SELECT * FROM users WHERE uid = " . $session['uid']); + } + + // ################################################################### + function _verifyCookieData() + { + return ($this->_fetchUserUsingCookies() != false); + } + + // ################################################################### + function _fetchUserWithIdentifier($string) + { + return $this->authDb->query_first("SELECT * FROM users WHERE name = '" . $this->authDb->escape_string($string) . "'"); + } + + // ################################################################### + function _verifyLoginUser($password) + { + return (md5($password) == $this->authUser['pass']); + } + + // ################################################################### + function clearCookies() + { + $this->registry->funct->cookie($this->cookieName); + $this->authDb->query("DELETE FROM sessions WHERE sid = '" . $this->authDb->escape_string($this->_fetchCookieUniqueId()) . "'"); + } + + // ################################################################### + function _setCookies($permanent = false) + { + $sid = $this->_fetchCookieUniqueId(); + $sid = ($sid ? $sid : md5(microtime() . rand())); + $this->registry->funct->cookie($this->cookieName, $sid, $permanent); + $this->authDb->query("REPLACE INTO sessions (sid, uid, hostname, timestamp) VALUES ('$sid', '" . $this->authUser['uid'] . "', '" . $this->authDb->escape_string($_SERVER['REMOTE_ADDR']) . "', " . time() . ")"); + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.22.5