PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | class/class-mainwp-api-manager-password-management.php +93 -93 4.6.0.1 → 6.2.2 View file →
@@ -10,9 +10,9 @@
10 10 namespace MainWP\Dashboard;
11 11
12 12 // Exit if accessed directly.
13 13 if ( ! defined( 'ABSPATH' ) ) {
14 - exit;
14 + exit;
15 15 }
16 16
17 17 /**
18 18 * Class MainWP_Api_Manager_Password_Management
@@ -23,108 +23,108 @@
23 23 * @author Todd Lahman LLC
24 24 * @copyright Copyright (c) Todd Lahman LLC
25 25 * @since 1.0.0
26 26 */
27 -class MainWP_Api_Manager_Password_Management {
27 +class MainWP_Api_Manager_Password_Management { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
28 28
29 - /**
30 - * Set encryption type.
31 - *
32 - * @var string $ENCRYPT
33 - */
34 - private static $ENCRYPT = 'AMEncrypt';
29 + /**
30 + * Set encryption type.
31 + *
32 + * @var string $ENCRYPT
33 + */
34 + private static $ENCRYPT = 'AMEncrypt';
35 35
36 - /**
37 - * Generate password. Creates a unique instance ID.
38 - *
39 - * @param int $length Length of ID.
40 - * @param bool $special_chars Valid special characters.
41 - * @param bool $extra_special_chars Extra special characters.
42 - *
43 - * @return string Password.
44 - */
45 - public static function generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) {
46 - $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
47 - if ( $special_chars ) {
48 - $chars .= '!@#$%^&*()';
49 - }
50 - if ( $extra_special_chars ) {
51 - $chars .= '-_ []{}<>~`+=,.;:/?|';
52 - }
36 + /**
37 + * Generate password. Creates a unique instance ID.
38 + *
39 + * @param int $length Length of ID.
40 + * @param bool $special_chars Valid special characters.
41 + * @param bool $extra_special_chars Extra special characters.
42 + *
43 + * @return string Password.
44 + */
45 + public static function generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) {
46 + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
47 + if ( $special_chars ) {
48 + $chars .= '!@#$%^&*()';
49 + }
50 + if ( $extra_special_chars ) {
51 + $chars .= '-_ []{}<>~`+=,.;:/?|';
52 + }
53 53
54 - $password = '';
55 - for ( $i = 0; $i < $length; $i++ ) {
56 - $password .= substr( $chars, wp_rand( 0, strlen( $chars ) - 1 ), 1 );
57 - }
54 + $password = '';
55 + for ( $i = 0; $i < $length; $i++ ) {
56 + $password .= substr( $chars, wp_rand( 0, strlen( $chars ) - 1 ), 1 );
57 + }
58 58
59 - // random_password filter was previously in random_password function which was deprecated.
60 - return $password;
61 - }
59 + // random_password filter was previously in random_password function which was deprecated.
60 + return $password;
61 + }
62 62
63 - /**
64 - * Encrypt string.
65 - *
66 - * @param string $str String to encrypt.
67 - *
68 - * @return string Encrypted string.
69 - */
70 - public static function encrypt_string( $str ) {
71 - return self::encrypt( $str, self::$ENCRYPT );
72 - }
63 + /**
64 + * Encrypt string.
65 + *
66 + * @param string $str String to encrypt.
67 + *
68 + * @return string Encrypted string.
69 + */
70 + public static function encrypt_string( $str ) {
71 + return static::encrypt( $str, static::$ENCRYPT );
72 + }
73 73
74 - /**
75 - * Decrypts string.
76 - *
77 - * @param string $encrypted Sting to decrypt.
78 - *
79 - * @return string Decrypted string.
80 - */
81 - public static function decrypt_string( $encrypted ) {
82 - return self::decrypt( $encrypted, self::$ENCRYPT );
83 - }
74 + /**
75 + * Decrypts string.
76 + *
77 + * @param string $encrypted Sting to decrypt.
78 + *
79 + * @return string Decrypted string.
80 + */
81 + public static function decrypt_string( $encrypted ) {
82 + return static::decrypt( $encrypted, static::$ENCRYPT );
83 + }
84 84
85 85
86 - /**
87 - * Encrypt.
88 - *
89 - * @param string $str String to encrypt.
90 - * @param string $pass String.
91 - *
92 - * @return string Encrypted string.
93 - */
94 - public static function encrypt( $str, $pass ) {
95 - if ( ! is_string( $str ) ) {
96 - return '';
97 - }
98 - $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) );
99 - $stra = str_split( $str );
100 - foreach ( $stra as $k => $v ) {
101 - $tmp = ord( $v ) + ord( $pass[ $k ] );
102 - $stra[ $k ] = chr( 255 < $tmp ? ( $tmp - 256 ) : $tmp );
103 - }
86 + /**
87 + * Encrypt.
88 + *
89 + * @param string $str String to encrypt.
90 + * @param string $pass String.
91 + *
92 + * @return string Encrypted string.
93 + */
94 + public static function encrypt( $str, $pass ) {
95 + if ( ! is_string( $str ) ) {
96 + return '';
97 + }
98 + $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) );
99 + $stra = str_split( $str );
100 + foreach ( $stra as $k => $v ) {
101 + $tmp = ord( $v ) + ord( $pass[ $k ] );
102 + $stra[ $k ] = chr( 255 < $tmp ? ( $tmp - 256 ) : $tmp );
103 + }
104 104
105 - return base64_encode( join( '', $stra ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
106 - }
105 + return base64_encode( join( '', $stra ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
106 + }
107 107
108 - /**
109 - * Decrypt.
110 - *
111 - * @param string $str String to Decrypt.
112 - * @param string $pass String.
113 - *
114 - * @return string Decrypted string.
115 - */
116 - public static function decrypt( $str, $pass ) {
117 - if ( ! is_string( $str ) ) {
118 - return '';
119 - }
120 - $str = base64_decode( $str ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
121 - $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) );
122 - $stra = str_split( $str );
123 - foreach ( $stra as $k => $v ) {
124 - $tmp = ord( $v ) - ord( $pass[ $k ] );
125 - $stra[ $k ] = chr( 0 > $tmp ? ( $tmp + 256 ) : $tmp );
126 - }
108 + /**
109 + * Decrypt.
110 + *
111 + * @param string $str String to Decrypt.
112 + * @param string $pass String.
113 + *
114 + * @return string Decrypted string.
115 + */
116 + public static function decrypt( $str, $pass ) {
117 + if ( ! is_string( $str ) ) {
118 + return '';
119 + }
120 + $str = base64_decode( $str ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
121 + $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) );
122 + $stra = str_split( $str );
123 + foreach ( $stra as $k => $v ) {
124 + $tmp = ord( $v ) - ord( $pass[ $k ] );
125 + $stra[ $k ] = chr( 0 > $tmp ? ( $tmp + 256 ) : $tmp );
126 + }
127 127
128 - return join( '', $stra );
129 - }
128 + return join( '', $stra );
129 + }
130 130 }