Location: PHPKode > projects > Aukyla Platform > doc/html/a00220.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>Aukyla PHP Framework</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="StyleSheet" href="auton.css" type="text/css" media="screen">
  </head>

  <body>
    <div id="mainmenu">
      <a href="http://www.auton.nl/" class="home">Home</a>
    </div>
    <div id="submenu">
      <a class="logo" href="http://www.auton.nl/"></a>

      <div class="head">Ads</div>
      <a href="http://sourceforge.net/"><img src="http://sourceforge.net/sflogo.php?group_id=116358&amp;type=1" alt="SourceForge.net Logo" style="padding: 2px 4px; width: 88px; height: 31px; border: 0px"></a>
      <a href="http://getfirefox.com/" title="Get Firefox - The Browser, Reloaded."><img src="http://www.mozilla.org/products/firefox/buttons/getfirefox_small.png" alt="Get Firefox" style="width: 110px; height: 32px; border: 0px"></a>
    </div>
    <div id="main">
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">base</a></div>
<h1>Login.php</h1><div class="fragment"><pre class="fragment">00001 &lt;?php
00002 <span class="comment">/*</span>
00003 <span class="comment">     Login.php, this module provides a login mechanism, including user and</span>
00004 <span class="comment">                session management</span>
00005 <span class="comment">     Copyright (C) 2003-2004 Arend van Beelen, Auton Rijnsburg</span>
00006 <span class="comment"></span>
00007 <span class="comment">     This program is free software; you can redistribute it and/or modify it</span>
00008 <span class="comment">     under the terms of the GNU General Public License as published by the Free</span>
00009 <span class="comment">     Software Foundation; either version 2 of the License, or (at your option)</span>
00010 <span class="comment">     any later version.</span>
00011 <span class="comment"></span>
00012 <span class="comment">     This program is distributed in the hope that it will be useful, but WITHOUT</span>
00013 <span class="comment">     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</span>
00014 <span class="comment">     FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for</span>
00015 <span class="comment">     more details.</span>
00016 <span class="comment"></span>
00017 <span class="comment">     You should have received a copy of the GNU General Public License along</span>
00018 <span class="comment">     with this program; if not, write to the Free Software Foundation, Inc.,</span>
00019 <span class="comment">     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
00020 <span class="comment"></span>
00021 <span class="comment"></span>
00022 <span class="comment">     For any questions, comments or whatever, you may mail me at: hide@address.com</span>
00023 <span class="comment">*/</span>
00024 
00025 require_once('<a class="code" href="a00092.html">Config</a>.php');
00026 require_once('Constants.php');
00027 require_once('<a class="code" href="a00119.html">Locale</a>.php');
00028 require_once('<a class="code" href="a00129.html">Messages</a>.php');
00029 require_once('<a class="code" href="a00152.html">Signal</a>.php');
00030 require_once('<a class="code" href="a00153.html">String</a>.php');
00031 
<a name="l00055"></a><a class="code" href="a00122.html">00055</a> <span class="keyword">class </span><a class="code" href="a00122.html">Login</a>
00056 {
<a name="l00069"></a><a class="code" href="a00122.html#a0">00069</a>         <span class="keyword">public</span> function __construct()
00070         {
00071                 $this-&gt;sessionVariables = array();
00072                 $this-&gt;username = 'anonymous';
00073 
00074                 $this-&gt;loginMethod = <a class="code" href="a00092.html#e0">Config::globals</a>('loginMethod', 'passwd');
00075 
00076                 $this-&gt;loadHandler($this-&gt;loginMethod);
00077 
00078                 <span class="comment">// restore the current session</span>
00079                 $this-&gt;restoreSession();
00080 
00081                 global $Login;
00082                 $Login = $this;
00083 
00084                 <span class="comment">// check whether the user filled in a login form</span>
00085                 <span class="keywordflow">if</span>(<a class="code" href="a00092.html#e2">Config::request</a>('action') == '<a class="code" href="a00122.html">Login</a>' &amp;&amp; <a class="code" href="a00092.html#e2">Config::request</a>('button') != i18n('Cancel'))
00086                 {
00087                         self::login(Config::request('username'), Config::request('password'));
00088                 }
00089                 elseif(getenv('AUKYLA_USER') != '' &amp;&amp; getenv('AUKYLA_PASSWORD') != '')
00090                 {
00091                         self::login(getenv('AUKYLA_USER'), getenv('AUKYLA_PASSWORD'));
00092                 }
00093         }
00094 
<a name="l00102"></a><a class="code" href="a00122.html#a1">00102</a>         <span class="keyword">public</span> function __destruct()
00103         {
00104                 $this-&gt;saveSessionVariables();
00105         }
00106 
<a name="l00115"></a><a class="code" href="a00122.html#e0">00115</a>         <span class="keyword">public</span> <span class="keyword">static</span> function login($username, $password)
00116         {
00117                 global $Login;
00118 
00119                 <span class="keywordflow">if</span>($Login-&gt;loginHandler-&gt;login($username, $password) == <span class="keyword">true</span>)
00120                 {
00121                         <span class="keywordflow">if</span>(isset($_SERVER['REMOTE_ADDR']) &amp;&amp;
00122                            <a class="code" href="a00153.html#e7">String::isIpInRange</a>($<a class="code" href="a00122.html">Login</a>-&gt;loginHandler-&gt;ipRange(Config::request('username')),
00123                                                $_SERVER['REMOTE_ADDR']) == <span class="keyword">false</span>)
00124                         {
00125                                 <a class="code" href="a00129.html#e0">Messages::error</a>(i18n('Sorry, you are not allowed to login from your current location.'));
00126                                 <a class="code" href="a00152.html#e1">Signal::emit</a>('Login::FailedLoginAttempt', Config::request('username'));
00127                                 $Login-&gt;loginHandler-&gt;logout();
00128                                 unset($<a class="code" href="a00122.html">Login</a>-&gt;loginHandler);
00129                                 $this-&gt;loadHandler($<a class="code" href="a00122.html">Login</a>-&gt;loginMethod);
00130                                 $this-&gt;restoreSession();
00131 
00132                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00133                         }
00134 
00135                         $Login-&gt;username = $username;
00136                         $Login-&gt;createSession($username);
00137                         $config = <span class="keyword">new</span> <a class="code" href="a00092.html">Config</a>('', $username);
00138                         <a class="code" href="a00119.html#e0">Locale::init</a>('base', $config-&gt;variable('language', 'en'));
00139                         <a class="code" href="a00129.html#e1">Messages::confirm</a>(i18n('Logged in successfully.'));
00140                         <a class="code" href="a00152.html#e1">Signal::emit</a>('Login::UserLoggedIn', $username);
00141 
00142                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
00143                 }
00144                 <span class="keywordflow">else</span>
00145                 {
00146                         <a class="code" href="a00129.html#e0">Messages::error</a>(i18n('Sorry, the username or password you provided is not valid.'));
00147                         <a class="code" href="a00152.html#e1">Signal::emit</a>('Login::FailedLoginAttempt', Config::request('username'));
00148                         <span class="keywordflow">if</span>(<a class="code" href="a00092.html#e2">Config::request</a>('action') == '<a class="code" href="a00122.html">Login</a>')
00149                         {
00150                                 <a class="code" href="a00092.html#e6">Config::unsetRequests</a>();
00151                                 <a class="code" href="a00092.html#e4">Config::setRequest</a>('view', '<a class="code" href="a00122.html">Login</a>');
00152                         }
00153                         unset($<a class="code" href="a00122.html">Login</a>-&gt;loginHandler);
00154                         $Login-&gt;loadHandler($<a class="code" href="a00122.html">Login</a>-&gt;loginMethod);
00155                         $Login-&gt;restoreSession();
00156 
00157                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00158                 }
00159         }
00160 
00167         <span class="keyword">public</span> <span class="keyword">static</span> function checkAction()
00168         {
00169                 <span class="comment">// check whether the user logged out</span>
00170                 <span class="keywordflow">if</span>(<a class="code" href="a00092.html#e2">Config::request</a>('action') == 'Logout')
00171                 {
00172                         <a class="code" href="a00122.html#e6">Login::logout</a>();
00173                         <a class="code" href="a00092.html#e6">Config::unsetRequests</a>();
00174                 }
00175         }
00176 
<a name="l00183"></a><a class="code" href="a00122.html#e2">00183</a>         <span class="keyword">public</span> <span class="keyword">static</span> function username()
00184         {
00185                 global $Login;
00186 
00187                 <span class="keywordflow">return</span> $Login-&gt;username;
00188         }
00189 
<a name="l00199"></a><a class="code" href="a00122.html#e3">00199</a>         <span class="keyword">public</span> <span class="keyword">static</span> function fullName($username = '')
00200         {
00201                 global $Login;
00202 
00203                 <span class="keywordflow">if</span>($username == '')
00204                 {
00205                         $username = $Login-&gt;username;
00206                 }
00207 
00208                 <span class="keywordflow">if</span>(<a class="code" href="a00153.html#e2">String::startsWith</a>($username, 'anonymous'))
00209                 {
00210                         <span class="keywordflow">return</span> i18n('Anonymous');
00211                 }
00212                 <span class="keywordflow">else</span>
00213                 {
00214                         <span class="keywordflow">return</span> $Login-&gt;loginHandler-&gt;fullName($username);
00215                 }
00216         }
00217 
<a name="l00227"></a><a class="code" href="a00122.html#e4">00227</a>         <span class="keyword">public</span> <span class="keyword">static</span> function userMail($username = '')
00228         {
00229                 global $Login;
00230 
00231                 <span class="keywordflow">if</span>($username == '')
00232                 {
00233                         $username = $Login-&gt;username;
00234                 }
00235 
00236                 <span class="keywordflow">if</span>(<a class="code" href="a00153.html#e2">String::startsWith</a>($username, 'anonymous'))
00237                 {
00238                         <span class="keywordflow">return</span> '';
00239                 }
00240                 <span class="keywordflow">else</span>
00241                 {
00242                         <span class="keywordflow">return</span> $Login-&gt;loginHandler-&gt;userMail($username);
00243                 }
00244         }
00245 
<a name="l00258"></a><a class="code" href="a00122.html#e5">00258</a>         <span class="keyword">public</span> <span class="keyword">static</span> function ipRange($username = '')
00259         {
00260                 global $Login;
00261 
00262                 <span class="keywordflow">if</span>($username == '')
00263                 {
00264                         $username = $Login-&gt;username;
00265                 }
00266 
00267                 <span class="keywordflow">if</span>(<a class="code" href="a00153.html#e2">String::startsWith</a>($username, 'anonymous'))
00268                 {
00269                         <span class="keywordflow">return</span> '';
00270                 }
00271                 <span class="keywordflow">else</span>
00272                 {
00273                         <span class="keywordflow">return</span> $Login-&gt;loginHandler-&gt;ipRange($username);
00274                 }
00275         }
00276 
<a name="l00280"></a><a class="code" href="a00122.html#e6">00280</a>         <span class="keyword">public</span> <span class="keyword">static</span> function logout()
00281         {
00282                 global $Config;
00283                 global $Login;
00284 
00285                 <span class="keywordflow">if</span>(!<a class="code" href="a00153.html#e2">String::startsWith</a>($<a class="code" href="a00122.html">Login</a>-&gt;username, 'anonymous'))
00286                 {
00287                         <a class="code" href="a00152.html#e1">Signal::emit</a>('Login::UserLoggedOut', $<a class="code" href="a00122.html">Login</a>-&gt;username);
00288                         $Login-&gt;loginHandler-&gt;logout();
00289                         $Login-&gt;destroySession();
00290                         $Config-&gt;readConfiguration();
00291 
00292                         unset($<a class="code" href="a00122.html">Login</a>-&gt;loginHandler);
00293                         $Login-&gt;loadHandler($<a class="code" href="a00122.html">Login</a>-&gt;loginMethod);
00294                         $Login-&gt;loginHandler-&gt;setUsername('anonymous');
00295                 }
00296 
00297                 <a class="code" href="a00129.html#e1">Messages::confirm</a>(i18n('Logged out successfully.'));
00298         }
00299 
<a name="l00309"></a><a class="code" href="a00122.html#e7">00309</a>         <span class="keyword">public</span> <span class="keyword">static</span> function setSessionVariable($variable, $value = <span class="keyword">false</span>)
00310         {
00311                 global $Login;
00312 
00313                 <span class="keywordflow">if</span>($value === <span class="keyword">false</span>)
00314                 {
00315                         unset($<a class="code" href="a00122.html">Login</a>-&gt;sessionVariables[$variable]);
00316                 }
00317                 <span class="keywordflow">else</span>
00318                 {
00319                         $Login-&gt;sessionVariables[$variable] = $value;
00320                 }
00321         }
00322 
<a name="l00334"></a><a class="code" href="a00122.html#e8">00334</a>         <span class="keyword">public</span> <span class="keyword">static</span> function sessionVariable($variable, $<span class="keywordflow">default</span> = '')
00335         {
00336                 global $Login;
00337 
00338                 <span class="keywordflow">if</span>(isset($<a class="code" href="a00122.html">Login</a>-&gt;sessionVariables[$variable]))
00339                 {
00340                         <span class="keywordflow">return</span> $Login-&gt;sessionVariables[$variable];
00341                 }
00342                 <span class="keywordflow">else</span>
00343                 {
00344                         <span class="keywordflow">return</span> $default;
00345                 }
00346         }
00347 
<a name="l00356"></a><a class="code" href="a00122.html#e9">00356</a>         <span class="keyword">public</span> <span class="keyword">static</span> function saveSessionVariables()
00357         {
00358                 global $Login;
00359 
00360                 <span class="keywordflow">if</span>(<span class="keyword">sizeof</span>($Login-&gt;sessionVariables) == 0)
00361                 {
00362                         <span class="keywordflow">return</span>;
00363                 }
00364 
00365                 <span class="keywordflow">if</span>($fp = fopen(AUKYLA_DIR.<span class="stringliteral">"/run/login/{$Login-&gt;username}"</span>, <span class="charliteral">'w'</span>))
00366                 {
00367                         foreach($<a class="code" href="a00122.html">Login</a>-&gt;sessionVariables as $variable =&gt; $value)
00368                         {
00369                                 fwrite($fp, <span class="stringliteral">"$variable=$value\n"</span>);
00370                         }
00371                         fclose($fp);
00372                 }
00373         }
00374 
<a name="l00380"></a><a class="code" href="a00122.html#e10">00380</a>         <span class="keyword">public</span> <span class="keyword">static</span> function users()
00381         {
00382                 global $Login;
00383 
00384                 <span class="keywordflow">return</span> $Login-&gt;loginHandler-&gt;users();
00385         }
00386 
<a name="l00396"></a><a class="code" href="a00122.html#e11">00396</a>         <span class="keyword">public</span> <span class="keyword">static</span> function usersOfGroup($group)
00397         {
00398                 global $Login;
00399 
00400                 <span class="keywordflow">return</span> $Login-&gt;loginHandler-&gt;usersOfGroup($group);
00401         }
00402 
<a name="l00408"></a><a class="code" href="a00122.html#e12">00408</a>         <span class="keyword">public</span> <span class="keyword">static</span> function groups()
00409         {
00410                 global $Login;
00411 
00412                 <span class="keywordflow">return</span> $Login-&gt;loginHandler-&gt;groups();
00413         }
00414 
<a name="l00424"></a><a class="code" href="a00122.html#e13">00424</a>         <span class="keyword">public</span> <span class="keyword">static</span> function memberGroups($username = '')
00425         {
00426                 global $Login;
00427 
00428                 <span class="keywordflow">if</span>($username == '')
00429                 {
00430                         $username = $Login-&gt;username;
00431                 }
00432 
00433                 <span class="keywordflow">return</span> $Login-&gt;loginHandler-&gt;memberGroups($username);
00434         }
00435 
<a name="l00443"></a><a class="code" href="a00122.html#e14">00443</a>         <span class="keyword">public</span> <span class="keyword">static</span> function isMemberOf($group)
00444         {
00445                 global $Login;
00446 
00447                 <span class="keywordflow">if</span>(isset($<a class="code" href="a00122.html">Login</a>-&gt;loginHandler) == <span class="keyword">false</span>)
00448                 {
00449                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00450                 }
00451 
00452                 <span class="keywordflow">return</span> (array_search($group, $<a class="code" href="a00122.html">Login</a>-&gt;loginHandler-&gt;memberGroups($<a class="code" href="a00122.html">Login</a>-&gt;username), <span class="keyword">true</span>) !== <span class="keyword">false</span>);
00453         }
00454 
00461         <span class="keyword">private</span> function createSession($username)
00462         {
00463                 global $UNITTEST;
00464 
00465                 <span class="comment">// generate a session id</span>
00466                 $sessionid = <a class="code" href="a00122.html#e15">Login::randomPassword</a>(32);
00467 
00468                 <span class="comment">// set initial session variables</span>
00469                 $this-&gt;sessionVariables = array('sessionid' =&gt; $sessionid,
00470                                                 'ip' =&gt; (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'));
00471 
00472                 <span class="comment">// set cookies in the user's browser</span>
00473                 <span class="keywordflow">if</span>(isset($UNITTEST) == <span class="keyword">false</span>)
00474                 {
00475                         <span class="keywordflow">if</span>(headers_sent() == <span class="keyword">false</span>)
00476                         {
00477                                 setcookie('username', $username, 0, <span class="charliteral">'/'</span>);
00478                                 setcookie('sessionid', $sessionid, 0, <span class="charliteral">'/'</span>);
00479                         }
00480                 }
00481                 <span class="keywordflow">else</span>
00482                 {
00483                         $_COOKIE['username'] = $username;
00484                         $_COOKIE['sessionid'] = $sessionid;
00485                 }
00486 
00487                 <span class="keywordflow">if</span>(<a class="code" href="a00153.html#e2">String::startsWith</a>($username, 'anonymous') == <span class="keyword">false</span>)
00488                 {
00489                         <span class="comment">// make normalBaseURL secure if logged in and we're staying in SSL mode</span>
00490                         <span class="keywordflow">if</span>(<a class="code" href="a00092.html#e0">Config::globals</a>('staySecure') == '<span class="keyword">true</span>')
00491                         {
00492                                 <a class="code" href="a00092.html#e1">Config::setGlobal</a>('baseURL', Config::globals('secureBaseURL'));
00493                                 <a class="code" href="a00092.html#e1">Config::setGlobal</a>('downloadURL', Config::globals('secureDownloadURL'));
00494                         }
00495                 }
00496                 $this-&gt;loginHandler-&gt;setUsername($username);
00497 
00498                 $this-&gt;username = $username;
00499 
00500                 <span class="keywordflow">return</span> $sessionid;
00501         }
00502 
00509         <span class="keyword">private</span> function restoreSession()
00510         {
00511                 <span class="keywordflow">if</span>(isset($_COOKIE['username']) &amp;&amp; isset($_COOKIE['sessionid']))
00512                 {
00513                         $username = $_COOKIE['username'];
00514 
00515                         <span class="comment">// open the session file</span>
00516                         <span class="keywordflow">if</span>(!file_exists(AUKYLA_DIR.<span class="stringliteral">"/run/login/$username"</span>) ||
00517                            ($lines = file(AUKYLA_DIR.<span class="stringliteral">"/run/login/$username"</span>)) === <span class="keyword">false</span>)
00518                         {
00519                                 Messages::error(i18n('Session rejected, possibly timed-out.'));
00520                                 $this-&gt;createSession('anonymous-'.$this-&gt;randomPassword(5));
00521                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00522                         }
00523 
00524                         <span class="comment">// check the session id and the ip address and read the session variables</span>
00525                         foreach($lines as $line)
00526                         {
00527                                 list($variable, $value) = explode(<span class="charliteral">'='</span>, trim($line), 2);
00528                                 <span class="keywordflow">if</span>(($variable == 'sessionid' &amp;&amp; $value != $_COOKIE['sessionid']) ||
00529                                    (isset($_SERVER['REMOTE_ADDR']) &amp;&amp; $variable == 'ip' &amp;&amp; $value != $_SERVER['REMOTE_ADDR']))
00530                                 {
00531                                         <a class="code" href="a00129.html#e0">Messages::error</a>(i18n('Session rejected because of invalid IP address or session ID.'));
00532                                         $this-&gt;sessionVariables = array();
00533                                         $this-&gt;createSession('anonymous-'.$this-&gt;randomPassword(5));
00534                                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
00535                                 }
00536 
00537                                 $this-&gt;sessionVariables[$variable] = $value;
00538                         }
00539 
00540                         $this-&gt;loginHandler-&gt;setUsername($username);
00541 
00542                         <span class="comment">// check if we're dealing with an anonymous user</span>
00543                         <span class="keywordflow">if</span>(<a class="code" href="a00153.html#e2">String::startsWith</a>($username, 'anonymous') == <span class="keyword">false</span>)
00544                         {
00545                                 <span class="comment">// make normalBaseURL secure if we're staying in SSL mode</span>
00546                                 <span class="keywordflow">if</span>(<a class="code" href="a00092.html#e0">Config::globals</a>('staySecure') == '<span class="keyword">true</span>')
00547                                 {
00548                                         <a class="code" href="a00092.html#e1">Config::setGlobal</a>('baseURL', Config::globals('secureBaseURL'));
00549                                         <a class="code" href="a00092.html#e1">Config::setGlobal</a>('downloadURL', Config::globals('secureDownloadURL'));
00550                                 }
00551                         }
00552 
00553                         $this-&gt;username = $username;
00554                         $config = <span class="keyword">new</span> <a class="code" href="a00092.html">Config</a>('', $username);
00555                         <a class="code" href="a00119.html#e0">Locale::init</a>('base', $config-&gt;variable('language', 'en'));
00556 
00557                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
00558                 }
00559                 <span class="keywordflow">else</span>
00560                 {
00561                         <span class="keywordflow">if</span>(<a class="code" href="a00092.html#e0">Config::globals</a>('uniqueAnonymousUsers', '<span class="keyword">true</span>') == '<span class="keyword">true</span>')
00562                         {
00563                                 $this-&gt;createSession('anonymous-'.$this-&gt;randomPassword(5));
00564                         }
00565                         <span class="keywordflow">else</span>
00566                         {
00567                                 $this-&gt;loginHandler-&gt;setUsername('anonymous');
00568                         }
00569                         <span class="keywordflow">return</span> <span class="keyword">true</span>; <span class="comment">// no session is restored, hence it did not fail</span>
00570                 }
00571         }
00572 
00578         <span class="keyword">private</span> function destroySession()
00579         {
00580                 global $UNITTEST;
00581 
00582                 $username = $this-&gt;loginHandler-&gt;username();
00583 
00584                 <span class="keywordflow">if</span>($username == '')
00585                 {
00586                         <span class="keywordflow">return</span>;
00587                 }
00588 
00589                 <span class="comment">// remove the session file</span>
00590                 unlink(AUKYLA_DIR.<span class="stringliteral">"/run/login/$username"</span>);
00591 
00592                 <span class="comment">// remove the cookies by setting their expiration time in the past</span>
00593                 <span class="keywordflow">if</span>(isset($UNITTEST) == <span class="keyword">false</span>)
00594                 {
00595                         setcookie('username', '', time() - 3600, <span class="charliteral">'/'</span>);
00596                         setcookie('sessionid', '', time() - 3600, <span class="charliteral">'/'</span>);
00597                 }
00598                 <span class="keywordflow">else</span>
00599                 {
00600                         unset($_COOKIE['username']);
00601                         unset($_COOKIE['sessionid']);
00602                 }
00603 
00604                 $this-&gt;username = 'anonymous';
00605 
00606                 $this-&gt;createSession('anonymous-'.$this-&gt;randomPassword(5));
00607 
00608                 <a class="code" href="a00119.html#e0">Locale::init</a>('base', Config::globals('language', 'en'));
00609         }
00610 
00620         <span class="keyword">private</span> function loadHandler($name)
00621         {
00622                 $className = self::handlerName($name);
00623                 <span class="keywordflow">if</span>(class_exists($className) == <span class="keyword">false</span>)
00624                 {
00625                         $include = @include_once(<span class="stringliteral">"LoginHandlers/$className.php"</span>);
00626                         <span class="keywordflow">if</span>($include == <span class="keyword">false</span> ||
00627                            class_exists($className) == <span class="keyword">false</span>)
00628                         {
00629                                 die('Unknown login method selected.');
00630                         }
00631                 }
00632 
00633                 $this-&gt;loginHandler = <span class="keyword">new</span> $className;
00634         }
00635 
00645         <span class="keyword">private</span> <span class="keyword">static</span> function handlerName($name)
00646         {
00647                 <span class="keywordflow">return</span> str_replace(array(<span class="charliteral">'/'</span>, <span class="charliteral">'-'</span>, <span class="charliteral">'.'</span>), <span class="charliteral">'_'</span>, $name).'_LoginHandler';
00648         }
00649 
<a name="l00657"></a><a class="code" href="a00122.html#e15">00657</a>         <span class="keyword">public</span> <span class="keyword">static</span> function randomPassword($len = 8)
00658         {
00659                 $pass = '';
00660                 $lchar = 0;
00661                 $char = 0;
00662                 <span class="keywordflow">for</span>($i = 0; $i &lt; $len; $i++)
00663                 {
00664                         <span class="keywordflow">while</span>($char == $lchar)
00665                         {
00666                                 $char = rand(48, 109);
00667                                 <span class="keywordflow">if</span>($char &gt; 57) $char += 7;
00668                                 <span class="keywordflow">if</span>($char &gt; 90) $char += 6;
00669                         }
00670                         $pass .= chr($<span class="keywordtype">char</span>);
00671                         $lchar = $char;
00672                 }
00673                 <span class="keywordflow">return</span> $pass;
00674         }
00675 
00676         <span class="keyword">private</span> $sessionVariables;
00677         <span class="keyword">private</span> $username;
00678         <span class="keyword">private</span> $loginHandler;
00679         <span class="keyword">private</span> $loginMethod;
00680 }
00681 
00682 <span class="comment">// create one global instance of the class and check actions from a previous form</span>
00683 global $Login;
00684 $Login = <span class="keyword">new</span> <a class="code" href="a00122.html">Login</a>();
00685 Login::checkAction();
00686 
00687 ?&gt;
</pre></div>    </div>
  </body>
</html>
Return current item: Aukyla Platform