Exemplo n.º 1
0
/**
 *    Check login and password with LDAP
 *    @return true when login & password both OK, false otherwise
 *    @author Roan Embrechts (based on code from Universit� Jean Monet)
 */
function ldap_login($login, $password)
{
    //error_log('Entering ldap_login('.$login.','.$password.')',0);
    $res = ldap_authentication_check($login, $password);
    // res=-1 -> the user does not exist in the ldap database
    // res=1 -> invalid password (user does exist)
    if ($res == 1) {
        //WRONG PASSWORD
        //$errorMessage = "LDAP User or password incorrect, try again.<br />";
        if (isset($log)) {
            unset($log);
        }
        if (isset($uid)) {
            unset($uid);
        }
        $loginLdapSucces = false;
    }
    if ($res == -1) {
        //WRONG USERNAME
        //$errorMessage =  "LDAP User or password incorrect, try again.<br />";
        $login_ldap_success = false;
    }
    if ($res == 0) {
        //LOGIN & PASSWORD OK - SUCCES
        //$errorMessage = "Successful login w/ LDAP.<br>";
        $login_ldap_success = true;
    }
    //$result = "This is the result: $errorMessage";
    $result = $login_ldap_success;
    return $result;
}
Exemplo n.º 2
0
require_once 'inc/authldap.php';
require_once "inc/functions.php";
//Forms posted
if (!empty($_POST)) {
    $errors = array();
    $username = sanitize(trim($_POST["username"]));
    $password = trim($_POST["password"]);
    //Perform some validation
    //Feel free to edit / change as required
    if ($username == "") {
        $errors[] = lang("ACCOUNT_SPECIFY_USERNAME");
    }
    if ($password == "") {
        $errors[] = lang("ACCOUNT_SPECIFY_PASSWORD");
    }
    $res = ldap_authentication_check($username, $password);
    // res=-1 -> the user does not exist in the ldap database
    // res=1 -> invalid password (user does exist)
    if ($res == 1) {
        $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
    }
    if ($res == -1) {
        $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
    }
    if ($res == 0) {
        // echo "<h1>LDAP OK for $username</h1>";
        if (!usernameExists($username)) {
            //First connexion, user needs to be added to SKEM Bank DB
            // After being created :
            // Change permision_id in sk_user_permission_matches to
            // 3 for admin