Esempio n. 1
0
                                    AND DATE_SUB(CURRENT_TIMESTAMP, interval " . intval(get_config('login_fail_deny_interval')) . " minute) < last_fail");
    }
    if (get_config('login_fail_check') && $r) {
        $ok = 8;
    } else {
        if (in_array($myrow->password, $auth_ids)) {
            $ok = alt_login($myrow, $uname, $pass);
        } else {
            $ok = login($myrow, $uname, $pass);
        }
    }

    if (isset($_SESSION['uid']) && $ok === 1) {
        Database::get()->query("INSERT INTO loginout (loginout.id_user, loginout.ip, loginout.when, loginout.action)
                                              VALUES (?d, ?s, NOW(), 'LOGIN')", intval($_SESSION['uid']), $_SERVER['REMOTE_ADDR']);
        resetLoginFailure();
        session_regenerate_id();
        set_session_mvars();
        echo session_id();
    } else {
        if ($ok === 4) {
            increaseLoginFailure();
        }
        echo RESPONSE_FAILED;
    }

    exit();
}

function set_session_mvars() {
    $status = array();
Esempio n. 2
0
function process_login()
{
    global $warning, $surname, $givenname, $email, $status, $is_admin, $language, $langInvalidId, $langAccountInactive1, $langAccountInactive2, $langNoCookies, $langEnterPlatform, $urlServer, $langHere, $auth_ids, $inactive_uid, $langTooManyFails;
    if (isset($_POST['uname'])) {
        $posted_uname = canonicalize_whitespace($_POST['uname']);
    } else {
        $posted_uname = '';
    }
    $pass = isset($_POST['pass']) ? $_POST['pass'] : '';
    $auth = get_auth_active_methods();
    $is_eclass_unique = is_eclass_unique();
    if (isset($_POST['submit'])) {
        unset($_SESSION['uid']);
        $auth_allow = 0;
        if (get_config('login_fail_check')) {
            $r = Database::get()->querySingle("SELECT 1 FROM login_failure WHERE ip = '" . $_SERVER['REMOTE_ADDR'] . "' \n                                        AND COUNT > " . intval(get_config('login_fail_threshold')) . " \n                                        AND DATE_SUB(CURRENT_TIMESTAMP, interval " . intval(get_config('login_fail_deny_interval')) . " minute) < last_fail");
        }
        if (get_config('login_fail_check') && $r) {
            $auth_allow = 8;
        } else {
            $sqlLogin = "******";
            if (get_config('case_insensitive_usernames')) {
                $sqlLogin = "******";
            } else {
                $sqlLogin = "******";
            }
            $myrow = Database::get()->querySingle("SELECT id, surname, givenname, password, username, status, email, lang, verified_mail\n                                FROM user WHERE username {$sqlLogin}", $posted_uname);
            //print_r($result);
            // cas might have alternative authentication defined
            $exists = 0;
            if (!isset($_COOKIE) or count($_COOKIE) == 0) {
                // Disallow login when cookies are disabled
                $auth_allow = 5;
            } elseif ($pass === '') {
                // Disallow login with empty password
                $auth_allow = 4;
            } else {
                if ($myrow) {
                    $exists = 1;
                    if (!empty($auth)) {
                        if (in_array($myrow->password, $auth_ids)) {
                            // alternate methods login
                            $auth_allow = alt_login($myrow, $posted_uname, $pass);
                        } else {
                            // eclass login
                            $auth_allow = login($myrow, $posted_uname, $pass);
                        }
                    } else {
                        $tool_content .= "<br>{$langInvalidAuth}<br>";
                    }
                }
            }
            if (!$exists and !$auth_allow) {
                Log::record(0, 0, LOG_LOGIN_FAILURE, array('uname' => $posted_uname, 'pass' => $pass));
                $auth_allow = 4;
            }
        }
        if (!isset($_SESSION['uid'])) {
            switch ($auth_allow) {
                case 1:
                    $warning .= "";
                    session_regenerate_id();
                    break;
                case 2:
                    $warning .= "<div class='alert alert-warning'>{$langInvalidId}</div>";
                    break;
                case 3:
                    $warning .= "<div class='alert alert-warning'>{$langAccountInactive1} " . "<a href='modules/auth/contactadmin.php?userid={$inactive_uid}&amp;h=" . token_generate("userid={$inactive_uid}") . "'>{$langAccountInactive2}</a></div>";
                    break;
                case 4:
                    $warning .= "<div class='alert alert-warning'>{$langInvalidId}</div>";
                    increaseLoginFailure();
                    break;
                case 5:
                    $warning .= "<div class='alert alert-warning'>{$langNoCookies}</div>";
                    break;
                case 6:
                    $warning .= "<div class='alert alert-warning'>{$langEnterPlatform} <a href='{$urlServer}secure/index.php'>{$langHere}</a></div>";
                    break;
                case 7:
                    $warning .= "<div class='alert alert-warning'>{$langEnterPlatform} <a href='{$urlServer}secure/cas.php'>{$langHere}</a></div>";
                    break;
                case 8:
                    $warning .= "<div class='alert alert-warning'>{$langTooManyFails}</div>";
                    break;
                default:
                    break;
            }
        } else {
            Database::get()->query("INSERT INTO loginout (loginout.id_user, loginout.ip, loginout.when, loginout.action) " . "VALUES ({$_SESSION['uid']}, '{$_SERVER['REMOTE_ADDR']}', NOW(), 'LOGIN')");
            if (get_config('email_verification_required') and get_mail_ver_status($_SESSION['uid']) == EMAIL_VERIFICATION_REQUIRED) {
                $_SESSION['mail_verification_required'] = 1;
                $next = "modules/auth/mail_verify_change.php";
            } elseif (isset($_POST['next'])) {
                $next = $_POST['next'];
            } else {
                $next = '';
            }
            resetLoginFailure();
            redirect_to_home_page($next);
        }
    }
    // end of user authentication
}
Esempio n. 3
0
function hybridauth_login() {
    //this is needed so as to include the HybridAuth error codes
    global $language, $language_codes, $siteName, $Institution, $InstitutionUrl;
    if (isset($language)) {
        // include_messages
        include "lang/$language/common.inc.php";
        $extra_messages = "config/{$language_codes[$language]}.inc.php";
        if (file_exists($extra_messages)) {
            include $extra_messages;
        } else {
            $extra_messages = false;
        }
        include "lang/$language/messages.inc.php";
        if ($extra_messages) {
            include $extra_messages;
        }
    }
    // end HybridAuth messages inclusion
    
    
    global $warning;
    
    // include HubridAuth libraries
    require_once 'modules/auth/methods/hybridauth/config.php';
    require_once 'modules/auth/methods/hybridauth/Hybrid/Auth.php';
    $config = get_hybridauth_config();
    
    // check for errors and whatnot
    $warning = '';
    
    if (isset($_GET['error'])) {
        Session::Messages(q(trim(strip_tags($_GET['error']))));
    }

    // if user select a provider to login with
    // then inlcude hybridauth config and main class
    // then try to authenticate te current user
    // finally redirect him to his profile page
    if (isset($_GET['provider'])) {
        try {
            // create an instance for Hybridauth with the configuration file path as parameter
            $hybridauth = new Hybrid_Auth($config);
            
            // set selected provider name
            $provider = @trim(strip_tags($_GET["provider"]));
        
            // try to authenticate the selected $provider
            $adapter = $hybridauth->authenticate( $provider );
            
            // grab the user profile
            $user_data = $adapter->getUserProfile();
            
            //user profile debug print
            //echo $user_data->displayName;
            //echo $user_data->email;
            //echo $user_data->photoURL;
            //echo $user_data->identifier;
            
        } catch (Exception $e) {
            // In case we have errors 6 or 7, then we have to use Hybrid_Provider_Adapter::logout() to
            // let hybridauth forget all about the user so we can try to authenticate again.
        
            // Display the recived error,
            // to know more please refer to Exceptions handling section on the userguide
            switch($e->getCode()) {
                case 0: Session::Messages($GLOBALS['langProviderError1']); break;
                case 1: Session::Messages($GLOBALS['langProviderError2']); break;
                case 2: Session::Messages($GLOBALS['langProviderError3']); break;
                case 3: Session::Messages($GLOBALS['langProviderError4']); break;
                case 4: Session::Messages($GLOBALS['langProviderError5']); break;
                case 5: Session::Messages($GLOBALS['langProviderError6']); break;
                case 6: Session::Messages($GLOBALS['langProviderError7']); $adapter->logout(); break;
                case 7: Session::Messages($GLOBALS['langProviderError8']); $adapter->logout(); break;
            }
        
            // debug messages for hybridauth errors
            //$warning .= "<br /><br /><b>Original error message:</b> " . $e->getMessage();
            //$warning .= "<hr /><pre>Trace:<br />" . $e->getTraceAsString() . "</pre>";
        
            return false;
        }
    } //endif( isset( $_GET["provider"] ) && $_GET["provider"] )
    
    
    // *****************************
    // from here on runs an alternative version of proccess_login() where
    // instead of a password, the provider user id is used and matched against
    // the corresponding field in the db table.
    global $surname, $givenname, $email, $status, $is_admin, $language,
    $langInvalidId, $langAccountInactive1, $langAccountInactive2,
    $langNoCookies, $langEnterPlatform, $urlServer, $langHere,
    $auth_ids, $inactive_uid, $langTooManyFails;
    
    $pass = $user_data->identifier; //password = provider user id
    $auth = get_auth_active_methods();
    //$is_eclass_unique = is_eclass_unique();
    
    unset($_SESSION['uid']);
    $auth_allow = 0;
    
    if (get_config('login_fail_check')) {
        $r = Database::get()->querySingle("SELECT 1 FROM login_failure WHERE ip = '" . $_SERVER['REMOTE_ADDR'] . "'
                                       AND COUNT > " . intval(get_config('login_fail_threshold')) . "
                                       AND DATE_SUB(CURRENT_TIMESTAMP, interval " . intval(get_config('login_fail_deny_interval')) . " minute) < last_fail");
    }
    if (get_config('login_fail_check') && $r) {
        $auth_allow = 8;
    } else {
        $auth_id = array_search(strtolower($provider), $auth_ids);
        $myrow = Database::get()->querySingle("SELECT user.id, surname,
                    givenname, password, username, status, email, lang,
                    verified_mail, uid
                FROM user, user_ext_uid
                WHERE user.id = user_ext_uid.user_id AND
                      user_ext_uid.auth_id = ?d AND
                      user_ext_uid.uid = ?s",
            $auth_id, $user_data->identifier);
        $exists = 0;
        if (!isset($_COOKIE) or count($_COOKIE) == 0) {
            // Disallow login when cookies are disabled
            $auth_allow = 5;
        } elseif ($myrow) {
            $exists = 1;
            if (!empty($auth)) {
                if (in_array($myrow->password, $auth_ids)) {
                    // alternate methods login
                    //$auth_allow = alt_login($myrow, $provider, $pass); //this should NOT be called during HybridAuth!
                } else {
                    // eclass login
                    $auth_allow = login($myrow, $provider, $pass, $provider);
                }
            } else {
                $tool_content .= "<br>$langInvalidAuth<br>";
            }
        }
        if (!$exists and !$auth_allow) {
            // Since HybridAuth was used and there is not user id matched in the db, send the user to the registration form.
            header('Location: ' . $urlServer . 'modules/auth/registration.php?provider=' . $provider);
            
            // from this point and on, the code does not need to run since the user is redirected to the registration page
            $auth_allow = 4;
        }
    }
    
    if (!isset($_SESSION['uid'])) {
        switch ($auth_allow) {
            case 1:
                session_regenerate_id();
                break;
            case 2:
                $warning .= "<p class='alert alert-warning'>$langInvalidId</p>";
                break;
            case 3:
                $warning .= "<p class='alert alert-warning'>$langAccountInactive1 " .
                    "<a href='modules/auth/contactadmin.php?userid=$inactive_uid&amp;h=" .
                    token_generate("userid=$inactive_uid") . "'>$langAccountInactive2</a></p>";
                break;
            case 4:
                $warning .= "<p class='alert alert-warning'>$langInvalidId</p>";
                increaseLoginFailure();
                break;
            case 5:
                $warning .= "<p class='alert alert-warning'>$langNoCookies</p>";
                break;
            case 6:
                $warning .= "<p class='alert alert-info'>$langEnterPlatform <a href='{$urlServer}secure/index.php'>$langHere</a></p>";
                break;
            case 7:
                $warning .= "<p class='alert alert-info'>$langEnterPlatform <a href='{$urlServer}modules/auth/cas.php'>$langHere</a></p>";
                break;
            case 8:
                $warning .= "<p class='alert alert-danger''>$langTooManyFails</p>";
                break;
        }
    } else {
        Database::get()->query("INSERT INTO loginout (loginout.id_user, loginout.ip, loginout.when, loginout.action) "
                . "VALUES ($_SESSION[uid], '$_SERVER[REMOTE_ADDR]', NOW(), 'LOGIN')");
        if (get_config('email_verification_required') and
            get_mail_ver_status($_SESSION['uid']) == EMAIL_VERIFICATION_REQUIRED) {
            $_SESSION['mail_verification_required'] = 1;
            $next = "modules/auth/mail_verify_change.php";
        } elseif (isset($_POST['next'])) {
            $next = $_POST['next'];
        } else {
            $next = '';
        }
        resetLoginFailure();
        redirect_to_home_page($next);
    }
}