# content-protector/4.1.4/inc/class-ps-conditional.php

Passster – Password Protect Pages and Content, version 4.1.4. 75 lines.

- Page: https://pluginprobe.com/plugins/content-protector/4.1.4/code/inc/class-ps-conditional.php
- Raw: https://pluginprobe.com/plugins/content-protector/4.1.4/raw/inc/class-ps-conditional.php
- Modified: 2023-05-31T10:07:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/content-protector/4.1.4/code/inc/class-ps-conditional.php#L10-L20`.

```php
<?php

namespace passster;

use  Exception ;
class PS_Conditional
{
    /**
     * Check if valid authentication exists.
     *
     * @param array $atts array of attributes.
     *
     * @return boolean
     * @throws Exception
     */
    public static function is_valid( array $atts ) : bool
    {
        $input = '';
        // is Cookie set?
        if ( !empty($_COOKIE['passster']) ) {
            $input = $_COOKIE['passster'];
        }
        // Valid password.
        if ( self::is_valid_password( $input, $atts ) ) {
            return true;
        }
        // captcha.
        if ( isset( $atts['captcha'] ) ) {
            if ( 'captcha' == $input ) {
                return true;
            }
        }
        // if nothing was correct.
        return false;
    }
    
    /**
     * Validate the password.
     *
     * @param string $input given password to validate.
     * @param array $atts given arguments to check.
     *
     * @return bool
     * @throws Exception
     */
    public static function is_valid_password( string $input, array $atts ) : bool
    {
        // password.
        
        if ( !empty($atts['password']) ) {
            $hash = hash_hmac( 'sha256', $atts['password'], get_option( 'passster_secure_key' ) );
            if ( hash_equals( $hash, $input ) ) {
                return true;
            }
        }
        
        return false;
    }
    
    /**
     * Maybe expire a password from a list by usage or time.
     *
     * @param string $password given password.
     * @param array $passwords_in_list passwords from list.
     *
     * @return void
     * @throws Exception
     */
    public static function maybe_expire_password_from_list( string $password, array $passwords_in_list, $list_id )
    {
        $should_delete = false;
        $key = array_search( $password, $passwords_in_list );
    }

}
```
