1. Go to this page and download the library: Download fuko-php/masked library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fuko-php / masked example snippets
use Fuko\Masked\Protect;
Protect::hideValue($secret_key); // hide the value inside the $secret_key var
Protect::hideInput('password', INPUT_POST); // hide the value of $_POST['password']
$redacted = Protect::protect($_POST);
// consider these values for the vars used
// $secret_key = '12345678';
// $_POST = array('username' => 'Bob', 'password' => 'WaldoPepper!', 'messages' => 'The secret key is 12345678');
$redacted = Protect::protect($_POST);
print_r($redacted);
/* ... and the output is
Array
(
[username] => Bob
[password] => ████████████
[messages] => The secret key is ████████
)
*/
use \Fuko\Masked\Protect;
// consider these values inside $config
// $config = array(
// 'project_title' => 'My New Project!',
// 'mysql_username' => 'me',
// 'mysql_password' => 'Mlyk!',
// 'mysql_database' => 'project',
// 'root' => '/var/www/niakade/na/majnata/si',
// 'i.am.stupid' => 'Mlyk! e egati parolata za moya project',
// );
Protect::hideValue($config['mysql_username']);
Protect::hideValue($config['mysql_password']);
Protect::hideValue($config['mysql_database']);
print_r(Protect::protect($config));
/* ... and the output is
Array
(
[project_title] => My New Project!
[mysql_username] => ██
[mysql_password] => █████
[mysql_database] => ███████
[root] => /var/www/niakade/na/majnata/si
[i.am.stupid] => █████ e egati parolata za moya ███████
)
*/
use \Fuko\Masked\Protect;
Protect::hideValue($password);
$a = ['b' => ['c' => ['d' => $password]]];
print_r(Protect::protect($a));
/* ... and the output is
Array
(
[b] => Array
(
[c] => Array
(
[d] => ██████
)
)
)
*/
use \Fuko\Masked\Protect;
Protect::hideInput('password', INPUT_POST);
// later you need to do a dump of $_POST and ...
$_POST_redacted = Protect::protect($_POST);
/* ... and the output is
Array
(
[email] => [email protected]
[password] => ███████
)
*/
use \Fuko\Masked\Protect;
Protect::hideValue($password);
$a = new stdClass;
$a->b = new stdClass;
$a->b->c = new stdClass;
$a->password = $a->b->secret = $a->b->c->d = $password;
echo Protect::protect(print_r($a, true));
/* ... and the output is
stdClass Object
(
[b] => stdClass Object
(
[c] => stdClass Object
(
[d] => ██████████████████
)
[secret] => ██████████████████
)
[password] => ██████████████████
)
*/
use \Fuko\Masked\Protect;
Protect::hideValue($password);
$e = new \Exception('Look, look, his password is ' . $password);
echo Protect::protect($e);
/* ... and the output is
Exception: Look, look, his password is ████████ in /tmp/egati-probata.php:123
Stack trace:
#0 {main}
*/
use \Fuko\Masked\Redact;
/* leave 4 chars unmasked at the end, and use '*' as masking symbol */
Redact::setRedactCallback( [Redact::class, 'disguise'], [4, '*']);
echo Redact::redact('1234567890'); // Output is '******7890'
/* leave 4 chars unmasked at the beginning, and use '🤐' as masking symbol */
Redact::setRedactCallback( [Redact::class, 'disguise'], [-4, '🤐']);
echo Redact::redact('1234567890'); // Output is '1234🤐🤐🤐🤐🤐🤐'
use \Fuko\Masked\Redact;
Redact::setRedactCallback( function($var) { return '💩'; } );
echo Redact::redact('1234567890'); // Output is '💩'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.