/**
 * Purge stored options from a permanent cookie
 *
 * LONG
 *
 * @access public
 * @param   array   Array of key names that shall be deleted inside cookies
 * @return null
 */
function serendipity_forgetCommentDetails($keys)
{
    global $serendipity;
    if (!$serendipity['COOKIE']) {
        return;
    }
    foreach ($keys as $n) {
        serendipity_deleteCookie($n);
    }
}
/**
 * Perform login to Serendipity
 *
 * @access public
 * @param   boolean     If set to true, external plugins will be queried for getting a login
 * @return  boolean     Return true, if the user is logged in. False if not.
 */
function serendipity_login($use_external = true)
{
    global $serendipity;
    if (serendipity_authenticate_author('', '', false, $use_external)) {
        #The session has this data already
        #we previously just checked the value of $_SESSION['serendipityAuthedUser'] but
        #we need the authorid still, so call serendipity_authenticate_author with blank
        #params
        return true;
    }
    // First try login via POST data. If true, the userinformation will be stored in a cookie (optionally)
    if (serendipity_authenticate_author($serendipity['POST']['user'], $serendipity['POST']['pass'], false, $use_external)) {
        if (empty($serendipity['POST']['auto'])) {
            serendipity_deleteCookie('author_information');
            serendipity_deleteCookie('author_information_iv');
            return false;
        } else {
            serendipity_issueAutologin(array('username' => $serendipity['POST']['user'], 'password' => $serendipity['POST']['pass']));
            return true;
        }
        // Now try login via COOKIE data
    } elseif (isset($serendipity['COOKIE']['author_information'])) {
        $cookie = serendipity_checkAutologin($serendipity['COOKIE']['author_information'], $serendipity['COOKIE']['author_information_iv']);
        $data = array('ext' => $use_external, 'mode' => 1, 'user' => $cookie['username'], 'pass' => $cookie['password']);
        serendipity_plugin_api::hook_event('backend_loginfail', $data);
        if (is_array($cookie) && serendipity_authenticate_author($cookie['username'], $cookie['password'], false, $use_external)) {
            return true;
        } else {
            serendipity_deleteCookie('author_information');
            serendipity_deleteCookie('author_information_iv');
            return false;
        }
    }
    $data = array('ext' => $use_external, 'mode' => 2, 'user' => $serendipity['POST']['user'], 'pass' => $serendipity['POST']['pass']);
    serendipity_plugin_api::hook_event('backend_loginfail', $data);
}