PluginProbe
Passster – Password Protect Pages and Content / 3.5.5.9
Passster – Password Protect Pages and Content v3.5.5.9
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 / src / class-ps-conditional.php

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

78 lines 2.2 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 // if nothing was correct.
28 return false;
29 }
30
31 /**
32 * @throws Exception
33 */
34 public static function is_valid_password( $input, $atts ) : bool
35 {
36 // password.
37
38 if ( !empty($atts['password']) ) {
39 $hash = hash_hmac( 'sha256', $atts['password'], get_option( 'passster_secure_key' ) );
40 if ( hash_equals( $hash, $input ) ) {
41 return true;
42 }
43 }
44
45 // passwords.
46
47 if ( !empty($atts['passwords']) ) {
48 $passwords = explode( ',', str_replace( ' ', '', $atts['passwords'] ) );
49 // Convert passwords to hashes.
50 foreach ( $passwords as $password ) {
51 $hash = hash_hmac( 'sha256', $password, get_option( 'passster_secure_key' ) );
52 if ( hash_equals( $hash, $input ) ) {
53 return true;
54 }
55 }
56 }
57
58 // password lists.
59
60 if ( !empty($atts['password_list']) ) {
61 $passwords_in_list = get_post_meta( $atts['password_list'], 'passster_passwords', true );
62 $passwords_in_list = explode( ',', $passwords_in_list );
63 // Convert passwords to hashes.
64 foreach ( $passwords_in_list as $password ) {
65 $hash = hash_hmac( 'sha256', $password, get_option( 'passster_secure_key' ) );
66
67 if ( hash_equals( $hash, $input ) ) {
68 self::maybe_expire_password_from_list__premium_only( $input, $passwords_in_list, $atts['password_list'] );
69 return true;
70 }
71
72 }
73 }
74
75 return false;
76 }
77
78 }