Пример #1
0
 /**
  * Log a user out of the LDAP server.
  *
  * Removes the cookies/session-vars set by setLoginDN()
  * after a user logs out using "auth_type" of "session" or "cookie".
  * Returns true on success, false on failure.
  *
  * @return bool True on success, false on failure.
  * @see setLoginDN
  */
 function unsetLoginDN()
 {
     if (DEBUG_ENABLED) {
         debug_log('%s:unsetLoginDN(): Entered with ()', 17, get_class($this));
     }
     if (!$this->auth_type) {
         return false;
     }
     switch ($this->auth_type) {
         case 'cookie':
             $logged_in_dn = $this->getLoggedInDN();
             if (!$logged_in_dn) {
                 return false;
             }
             $logged_in_pass = $this->getLoggedInPass();
             $anon_bind = $logged_in_dn == 'anonymous' ? true : false;
             # set cookie with expire time already passed to erase cookie from client
             $expire = time() - 3600;
             $cookie_dn_name = sprintf('pla_login_dn_%s', $this->server_id);
             $cookie_pass_name = sprintf('pla_login_pass_%s', $this->server_id);
             if ($anon_bind) {
                 $res1 = pla_set_cookie($cookie_dn_name, 'anonymous', $expire);
                 $res2 = pla_set_cookie($cookie_pass_name, '0', $expire);
             } else {
                 $res1 = pla_set_cookie($cookie_dn_name, pla_blowfish_encrypt($logged_in_dn), $expire);
                 $res2 = pla_set_cookie($cookie_pass_name, pla_blowfish_encrypt($logged_in_pass), $expire);
             }
             # Need to unset the cookies too, since they are still set if further processing occurs (eg: Timeout)
             unset($_COOKIE[$cookie_dn_name]);
             unset($_COOKIE[$cookie_pass_name]);
             if (!$res1 || !$res2) {
                 return false;
             } else {
                 return true;
             }
             break;
         case 'session':
             # unset session variables
             $session_var_dn_name = sprintf('pla_login_dn_%s', $this->server_id);
             $session_var_pass_name = sprintf('pla_login_pass_%s', $this->server_id);
             if (array_key_exists($session_var_dn_name, $_SESSION)) {
                 unset($_SESSION[$session_var_dn_name]);
             }
             if (array_key_exists($session_var_pass_name, $_SESSION)) {
                 unset($_SESSION[$session_var_pass_name]);
             }
             return true;
             break;
         default:
             pla_error(sprintf(_('Unknown auth_type: %s'), htmlspecialchars($auth_type)));
             break;
     }
 }
Пример #2
0
    $password = '******';
    foreach (array('md5', 'md5crypt', 'sha', 'ssha', 'smd5', 'crypt', 'clear') as $enc_type) {
        $crypted_password = password_hash($password, $enc_type);
        print "[" . $enc_type . "] " . $crypted_password . "<br />";
        print "  Test: " . (password_check($crypted_password, $password) ? "passed" : "failed");
        print "\n";
        //unset($crypted_password);
        flush();
    }
}
if (true) {
    $secret = "foobar";
    $passwords = array('fun!244A', 'asdf', 'dc=stuff,ou=things', 'y()ikes');
    $passwords_encrypted = array();
    foreach ($passwords as $password) {
        $passwords_encrypted[] = pla_blowfish_encrypt($password, $secret);
    }
    $passwords_decrypted = array();
    foreach ($passwords_encrypted as $password) {
        $passwords_decrypted[] = pla_blowfish_decrypt($password, $secret);
    }
    foreach ($passwords_decrypted as $i => $password) {
        echo $passwords[$i] . ': ' . $passwords_encrypted[$i] . '<br />    ';
        if ($passwords[$i] == $passwords_decrypted[$i]) {
            echo "passed<br />";
        } else {
            echo "<b>failed!</b></br />";
        }
    }
}
print password_generate();