• Hello Ben,

    I am a great fan and user of your ‘Password Protected’ wordpress plugin. I use it a lot on my sites.

    I have a query. After a user enters the password and logs in, how much time till the cookie clears and asks for password again. I want to change the time to less than 2 hours.

    Also, how can I customize the ‘Password’ text on login page.

    Thank you.

    Regards,
    Mahendar.

    https://wordpress.org/plugins/password-protected/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    You can set a different expire time using the password_protected_auth_cookie_expiration filter.

    // Expire after 2 hours
    function my_password_protected_auth_cookie_expiration( $duration ) {
        return 7200 // Time in seconds
    }
    add_filter( 'password_protected_auth_cookie_expiration', 'my_password_protected_auth_cookie_expiration' );

    Which Password text do you want to change?
    The word “Password”?
    You would need to use the WordPress gettext filter.

    You can add content above the login fields using the password_protected_before_login_form action;

    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 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Customize text and change cookie time’ is closed to new replies.