Forum Replies Created

Viewing 1 replies (of 1 total)
  • Hi,

    thanks for a grade plugin, but could you please clarify (I am not an expert), where to change the cookie expiration time?

    Is it somewhere here?

    ‘/**
    * Generate Auth Cookie
    *
    * @param int $expiration Expiration time in seconds.
    * @param string $scheme Cookie scheme.
    * @return string Cookie.
    */
    function generate_auth_cookie( $expiration, $scheme = ‘auth’ ) {

    $pass = md5( get_option( ‘password_protected_password’ ) );
    $pass_frag = substr( $pass, 8, 4 );

    $key = md5( $this->get_site_id() . $pass_frag . ‘|’ . $expiration );
    $hash = hash_hmac( ‘md5’, $this->get_site_id() . ‘|’ . $expiration, $key );
    $cookie = $this->get_site_id() . ‘|’ . $expiration . ‘|’ . $hash;

    return $cookie;

    }

    /**
    * Parse Auth Cookie
    *
    * @param string $cookie Cookie string.
    * @param string $scheme Cookie scheme.
    * @return string Cookie string.
    */
    function parse_auth_cookie( $cookie = ”, $scheme = ” ) {

    if ( empty( $cookie ) ) {
    $cookie_name = $this->cookie_name();

    if ( empty( $_COOKIE[$cookie_name] ) ) {
    return false;
    }
    $cookie = $_COOKIE[$cookie_name];
    }

    $cookie_elements = explode( ‘|’, $cookie );
    if ( count( $cookie_elements ) != 3 ) {
    return false;
    }

    list( $site_id, $expiration, $hmac ) = $cookie_elements;

    return compact( ‘site_id’, ‘expiration’, ‘hmac’, ‘scheme’ );

    }

    /**
    * Set Auth Cookie
    *
    * @todo
    *
    * @param boolean $remember Remember logged in.
    * @param string $secure Secure cookie.
    */
    function set_auth_cookie( $remember = false, $secure = ”) {

    if ( $remember ) {
    $expiration = $expire = current_time( ‘timestamp’ ) + apply_filters( ‘password_protected_auth_cookie_expiration’, 1209600, $remember );
    } else {
    $expiration = current_time( ‘timestamp’ ) + apply_filters( ‘password_protected_auth_cookie_expiration’, 604800, $remember );
    $expire = 0;
    }

    if ( ” === $secure ) {
    $secure = is_ssl();
    }

    $secure_password_protected_cookie = apply_filters( ‘password_protected_secure_password_protected_cookie’, false, $secure );
    $password_protected_cookie = $this->generate_auth_cookie( $expiration, ‘password_protected’ );

    setcookie( $this->cookie_name(), $password_protected_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure_password_protected_cookie, true );
    if ( COOKIEPATH != SITECOOKIEPATH ) {
    setcookie( $this->cookie_name(), $password_protected_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_password_protected_cookie, true );
    }

    }

    /**
    * Clear Auth Cookie
    */
    function clear_auth_cookie() {

    setcookie( $this->cookie_name(), ‘ ‘, current_time( ‘timestamp’ ) – 31536000, COOKIEPATH, COOKIE_DOMAIN );
    setcookie( $this->cookie_name(), ‘ ‘, current_time( ‘timestamp’ ) – 31536000, SITECOOKIEPATH, COOKIE_DOMAIN );

    }

    /**
    * Cookie Name
    *
    * @return string Cookie name.
    */
    function cookie_name() {

    return $this->get_site_id() . ‘_password_protected_auth’;

    }’

    Thanks for your help,

Viewing 1 replies (of 1 total)