PluginProbe
Passster – Password Protect Pages and Content / 4.2.10
Passster – Password Protect Pages and Content v4.2.10
4.3.15 4.3.14 4.3.12 4.3.13 4.3.11 4.3.10 4.3.9 4.3.8 4.3.7 4.3.6 4.3.5 trunk 3.5.4 3.5.5.2 3.5.5.8 3.5.5.9 4.0 4.1.4 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.15 4.2.16 All 47 releases
content-protector / inc / class-ps-conditional.php

class-ps-conditional.php in Passster – Password Protect Pages and Content 4.2.10, at inc/class-ps-conditional.php

56 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace passster;
4
5 use Exception;
6 class PS_Conditional {
7 /**
8 * Check if valid authentication exists.
9 *
10 * @param array $atts array of attributes.
11 *
12 * @return boolean
13 * @throws Exception
14 */
15 public static function is_valid( array $atts ) : bool {
16 $input = '';
17 // is Cookie set?
18 if ( !empty( $_COOKIE['passster'] ) ) {
19 $input = esc_html( $_COOKIE['passster'] );
20 }
21 // Valid password.
22 if ( self::is_valid_password( $input, $atts ) ) {
23 return true;
24 }
25 // captcha.
26 if ( isset( $atts['captcha'] ) ) {
27 if ( 'captcha' == $input ) {
28 return true;
29 }
30 }
31 // if nothing was correct.
32 return false;
33 }
34
35 /**
36 * Validate the password.
37 *
38 * @param string $input given password to validate.
39 * @param array $atts given arguments to check.
40 *
41 * @return bool
42 * @throws Exception
43 */
44 public static function is_valid_password( string $input, array $atts ) : bool {
45 // password.
46 if ( !empty( $atts['password'] ) ) {
47 $hash = hash_hmac( 'sha256', esc_html( $atts['password'] ), get_option( 'passster_secure_key' ) );
48 if ( hash_equals( $hash, $input ) ) {
49 return true;
50 }
51 }
52 return false;
53 }
54
55 }
56