• Resolved DC38746

    (@dc38746)


    Hi, I just started using the plugin, it works brilliantly, thanks!

    I have a page with a password form, which redirects on success. However, if someone returns to that page later, the password form is gone and the redirect doesn’t occur. I found the list of action hooks, but none seem to work in my situation, passster_validation_success for instance seems to only work if the form is submitted, not a more global “is_validated” type check.

    What I’m hoping for is a way to check whether the password for a given page is valid, and then redirect if it is. Any built in way to do this?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter DC38746

    (@dc38746)

    Quick update and a bit of a hack, I created a custom shortcode in functions.php, used do_shortcode to load the returned value of the Passter shortcode into a variable, then either return that value or redirect if it’s empty — it works! If there’s a built-in hook for this I’d still love to know since that would be cleaner, but if not, maybe this can help someone else.

    Hey @dc38746,

    I think your solution is quite valid!

    The problem is that after passster_validation_success the password is already encrypted, so comparing would only work with a hash comparison (which might be overkill for your use case).

    $atts  = array( 'password' => 'my-password' );
    $valid = passster\PS_Conditional::is_valid( $atts );
    
    if ( $valid ) {
    	// Trigger the redirect.
    }
    
    // Redirecting per specific password.
    $atts     = array( 'password' => 'my-password' );
    $password = 'my-password';
    
    $valid = passster\PS_Conditional::is_valid( $atts );
    
    if ( $valid ) {
    	$hash = hash_hmac( 'sha256', $atts['password'], get_option( 'passster_secure_key' ) );
    
    	if ( hash_equals( $hash, $password ) ) {
    		// Trigger the redirect.
    	}
    }

    Thread Starter DC38746

    (@dc38746)

    Oh interesting! Thanks for that, that probably jump starts one of the next phases I need to work on, allowing a client to update the stored password in a central place, probably an ACF custom field on an options page. It looks like you have really good documentation for all of these things though, so I imagine I’ll figure it out.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hook to check validated status?’ is closed to new replies.