PluginProbe
Passster – Password Protect Pages and Content / 4.0
Passster – Password Protect Pages and Content v4.0
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.0, at inc/class-ps-conditional.php

60 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 /**
9 * Check if valid authentication exists.
10 *
11 * @param array $atts array of attributes.
12 *
13 * @return boolean
14 * @throws Exception
15 */
16 public static function is_valid( array $atts ) : bool
17 {
18 $input = '';
19 // is Cookie set?
20 if ( !empty($_COOKIE['passster']) ) {
21 $input = $_COOKIE['passster'];
22 }
23 // Valid password.
24 if ( self::is_valid_password( $input, $atts ) ) {
25 return true;
26 }
27 // captcha.
28 if ( isset( $atts['captcha'] ) ) {
29 if ( 'captcha' == $input ) {
30 return true;
31 }
32 }
33 // if nothing was correct.
34 return false;
35 }
36
37 /**
38 * Validate the password.
39 *
40 * @param string $input given password to validate.
41 * @param array $atts given arguments to check.
42 *
43 * @return bool
44 * @throws Exception
45 */
46 public static function is_valid_password( string $input, array $atts ) : bool
47 {
48 // password.
49
50 if ( !empty($atts['password']) ) {
51 $hash = hash_hmac( 'sha256', $atts['password'], get_option( 'passster_secure_key' ) );
52 if ( hash_equals( $hash, $input ) ) {
53 return true;
54 }
55 }
56
57 return false;
58 }
59
60 }