function task_captchapack($task)
{
    global $db;
    // Delete old captcha entries, those older than one hour
    $cut = TIME_NOW - 60 * 60 * captchapack_gets_num('cleanupinterval', 1);
    $db->delete_query("captcha_captchapack", "dateline < '{$cut}'");
}
/**
 * Validation callback function.
 */
function captchapack_validate($reg)
{
    global $mybb, $db, $lang;
    // Quit if it's not enabled
    if (!$mybb->settings['captchapack_enabled']) {
        return;
    }
    // Load error messages
    $lang->load('captchapack');
    // Quit if the hash field is gone
    if (empty($mybb->input['captchapack-hash'])) {
        $reg->set_error($lang->captchapack_error_no_hash);
        return;
    }
    // Quit if hash in invalid
    if (!preg_match('/^[0-9a-f]{40}$/', $mybb->input['captchapack-hash'])) {
        $reg->set_error($lang->captchapack_error_invalid_hash);
        return;
    }
    // Validate
    $hash = $mybb->input['captchapack-hash'];
    if (isset($mybb->input['captchapack-answer']) && '' !== $mybb->input['captchapack-answer']) {
        $answer = trim($mybb->input['captchapack-answer']);
        // Filter out answers that don't follow the correct format to save one
        // database query. Note this also means changing the CAPTCHA length
        // invalidates existing CAPTCHAs.
        $num = captchapack_gets_num('num', 5);
        $type = $mybb->settings['captchapack_type'];
        if (in_array($type, array('asciiart', 'css', 'route')) && !preg_match("/^\\w{{$num}}\$/", $answer)) {
            $reg->set_error($lang->captchapack_error_invalid_fmt);
        } else {
            $result = captchapack_dbvalidate($hash, $answer);
            if (!$result) {
                $reg->set_error($lang->captchapack_error_invalid_ans);
            } elseif (captchapack_gets_num('minresptime', 0) && $result > TIME_NOW - captchapack_gets_num('minresptime', 0)) {
                $reg->set_error($lang->captchapack_error_too_fast);
            }
        }
    } else {
        $reg->set_error($lang->captchapack_error_no_ans);
    }
    // Drop all entries with the hash
    captchapack_dbdrop($hash);
}