Changeset 1858 in ExiteCMS for trunk/includes/user_functions.php


Ignore:
Timestamp:
10/17/08 16:40:38 (4 years ago)
Author:
hverton
Message:

rewritten the login/logout code, all code is now located in setuser.php
added a security setting "require SSL for logins"
added a security setting "require login before site access"
fixed small date display issue in several rev. upgrade files
added alternative login methods to the full-screen login

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/user_functions.php

    r1840 r1858  
    5656} 
    5757 
    58 // Check if a user wants to logging in 
    59 if (isset($_POST['login'])) { 
    60     $auth_result = false; 
    61     $auth_methods = isset($settings['auth_type']) ? explode(",",$settings['auth_type'].",") : array('local'); 
    62     foreach($auth_methods as $auth_method) { 
    63         switch($auth_method) { 
    64             case "local": 
    65                 // authentication against the local user database 
    66                 if (!empty($_POST['user_name']) && !empty($_POST['user_pass'])) { 
    67                     $auth_result = auth_local($_POST['user_name'], $_POST['user_pass']); 
    68                 } 
    69                 break; 
    70             case "ldap": 
    71                 break; 
    72             case "ad": 
    73                 break; 
    74             case "openid": 
    75                 // authentication against an openid provider 
    76                 if (!empty($_POST['user_openid_url'])) { 
    77                     $auth_result = auth_openid($_POST['user_openid_url']); 
    78                 } 
    79                 break; 
    80             case "default": 
    81                 // empty or unknown entry, ignore 
    82                 break; 
    83         } 
    84     } 
    85     // check the result of the authentication attempt, and process it 
    86     if (is_array($auth_result)) { 
    87         switch($auth_result[0]) { 
    88             case "redirect": 
    89                 redirect($auth_result[1], $auth_result[2]); 
    90                 exit;  
    91             default: 
    92                 // unknown result code 
    93                 _debug($auth_result); 
    94                 terminate("unknown result code from an authentication module!"); 
    95         } 
    96     } 
    97 } 
    98  
    99 // if not in the process of posting a form, did the login session expired? 
     58// if not in the process of posting a form, did the login session expire? 
    10059if (count($_POST)==0 && !empty($_SESSION['login_expire']) && $_SESSION['login_expire'] < time()) { 
    10160    // clear the login info from the session 
     
    164123    } 
    165124} else { 
     125    // is login required? 
     126    if ($settings['auth_required'] && FUSION_SELF != "login.php" && FUSION_SELF != "setuser.php") { 
     127        redirect(BASEDIR."login.php", "script"); 
     128        exit; 
     129    } 
    166130    define("PATH_THEME", PATH_THEMES.$settings['theme']."/"); 
    167131    define("THEME", THEMES.$settings['theme']."/"); 
     
    275239        // deny all non-webmasters access to the site 
    276240        redirect(BASEDIR.'maintenance.php?reason='.$settings['maintenance']); 
    277     } 
    278 } 
    279  
    280  
    281 /*---------------------------------------------------+ 
    282 | User authentication functions                      | 
    283 +----------------------------------------------------*/ 
    284  
    285 // authentication against the local user database 
    286 function auth_local($userid, $password) { 
    287     global $db_prefix; 
    288      
    289     // check and validate the given userid and pasword 
    290     $user_pass = md5(md5($password)); 
    291     $user_name = preg_replace(array("/\=/","/\#/","/\sOR\s/"), "", stripinput($userid)); 
    292  
    293     // check if we have a user record for this userid and password 
    294     $result = dbquery("SELECT * FROM ".$db_prefix."users WHERE user_name='$user_name' AND user_password='".$user_pass."'"); 
    295     if (dbrows($result) == 0) { 
    296         // not found, display an error message 
    297         return array("redirect", BASEDIR."setuser.php?error=3", "script"); 
    298     } else { 
    299         // found, get the record and do some more validation 
    300         $ret = auth_user_validate(dbarray($result)); 
    301         return $ret; 
    302     } 
    303 } 
    304  
    305 // authentication against an LDAP server 
    306 function auth_ldap($userid, $password) { 
    307     return array('auth_ldap not defined yet!'); 
    308 } 
    309  
    310 // authentication against an Active Directory server 
    311 function auth_ad($userid, $password) { 
    312     return array('auth_ad not defined yet!'); 
    313 } 
    314  
    315 // authentication using an OpenID 
    316 function auth_openid($openid_url) { 
    317     global $settings; 
    318  
    319     // check if the URL is valid 
    320     if (isURL($openid_url)) { 
    321         require_once(PATH_INCLUDES."class.openid.php"); 
    322         $openid = new SimpleOpenID; 
    323         $openid->SetIdentity($openid_url); 
    324         $openid->SetApprovedURL($settings['siteurl']."setuser.php"); 
    325         $openid->SetTrustRoot($settings['siteurl']); 
    326         $server_url = $openid->GetOpenIDServer(); 
    327         if ($server_url) { 
    328             return array("redirect", $openid->GetRedirectURL() , "script"); 
    329         } 
    330     } else { 
    331         // for now... 
    332         return false; 
    333     } 
    334 } 
    335  
    336 // further validation on the userid found 
    337 function auth_user_validate($userrecord) { 
    338  
    339     // if the account is suspended, check for an expiry date 
    340     if ($userrecord['user_status'] == 1 && $userrecord['user_ban_expire'] > 0 && $userrecord['user_ban_expire'] < time() ) { 
    341         // if this user's email address is marked as bad, reset the countdown counter 
    342         $userrecord['user_bad_email'] = $userrecord['user_bad_email'] == 0 ? 0 : time(); 
    343         // reset the user status and the expiry date 
    344         $result = dbquery("UPDATE ".$db_prefix."users SET user_status='0', user_ban_expire='0', user_bad_email = '".$userrecord['user_bad_email']."' WHERE user_id='".$userrecord['user_id']."'"); 
    345         $userrecord['user_status'] = 0; 
    346     } 
    347     if ($userrecord['user_status'] == 0) {   
    348         header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'"); 
    349         // set the 'remember me' status value  
    350         $_SESSION['remember_me'] = isset($_POST['remember_me']) ? "yes" : "no"; 
    351         $_SESSION['userinfo'] = $userrecord['user_id'].".".$userrecord['user_password']; 
    352         // login expiry defined? 
    353         if ($settings['login_expire']) { 
    354             if (isset($_POST['remember_me']) && $_POST['remember_me'] == "yes") { 
    355                 $_SESSION['login_expire'] = time() + $settings['login_extended_expire']; 
    356             } else { 
    357                 $_SESSION['login_expire'] = time() + $settings['login_expire']; 
    358             } 
    359         } else { 
    360             $_SESSION['login_expire'] = mktime(0,0,0,1,1,2038); // do not expire 
    361         } 
    362         return array("redirect", BASEDIR."setuser.php?user=".$userrecord['user_name'], "script"); 
    363     } elseif ($userrecord['user_status'] == 1) { 
    364         return array("redirect", BASEDIR."setuser.php?user_id=".$userrecord['user_id']."&error=1", "script"); 
    365     } elseif ($userrecord['user_status'] == 2) { 
    366         return array("redirect", BASEDIR."setuser.php?error=2", "script"); 
    367241    } 
    368242} 
Note: See TracChangeset for help on using the changeset viewer.