~`+=,.;:/?|'; } $password = ''; for ( $i = 0; $i < $length; $i++ ) { $password .= substr( $chars, wp_rand( 0, strlen( $chars ) - 1 ), 1 ); } // random_password filter was previously in random_password function which was deprecated. return $password; } /** * Encrypt string. * * @param string $str String to encrypt. * * @return string Encrypted string. */ public static function encrypt_string( $str ) { return static::encrypt( $str, static::$ENCRYPT ); } /** * Decrypts string. * * @param string $encrypted Sting to decrypt. * * @return string Decrypted string. */ public static function decrypt_string( $encrypted ) { return static::decrypt( $encrypted, static::$ENCRYPT ); } /** * Encrypt. * * @param string $str String to encrypt. * @param string $pass String. * * @return string Encrypted string. */ public static function encrypt( $str, $pass ) { if ( ! is_string( $str ) ) { return ''; } $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) ); $stra = str_split( $str ); foreach ( $stra as $k => $v ) { $tmp = ord( $v ) + ord( $pass[ $k ] ); $stra[ $k ] = chr( 255 < $tmp ? ( $tmp - 256 ) : $tmp ); } return base64_encode( join( '', $stra ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. } /** * Decrypt. * * @param string $str String to Decrypt. * @param string $pass String. * * @return string Decrypted string. */ public static function decrypt( $str, $pass ) { if ( ! is_string( $str ) ) { return ''; } $str = base64_decode( $str ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) ); $stra = str_split( $str ); foreach ( $stra as $k => $v ) { $tmp = ord( $v ) - ord( $pass[ $k ] ); $stra[ $k ] = chr( 0 > $tmp ? ( $tmp + 256 ) : $tmp ); } return join( '', $stra ); } }