Giter Site home page Giter Site logo

laravel-conceal's Introduction

Laravel Conceal

Author Build Packagist Version Software License

This package allows you to conceal sensitive data in arrays and collections. This is particularly useful when writing possibly sensitive data to log files.

Once installed you can do things like this:

$data = [
    'username' => 'wouter',
    'api_key' => 'secret'
];

$hide = ['api_key'];

$output = conceal($data, $hide);
print_r($output);

// Outputs: ['username' => 'wouter', 'api_key' => '********']

Requirements

  • PHP >= 7.2
  • Laravel 5.7+ | 6 | 7 | 8

Installation

Install the package via composer:

composer require kielabokkie/laravel-conceal

Package configuration

This package has minimal configuration. All you can do at the moment is set the keys that are concealed by default. If you want to add your own defaults you can do that by publishing the config file by running the following command:

php artisan vendor:publish --provider="Kielabokkie\LaravelConceal\ConcealServiceProvider"

These are the contents of the file that will be published at config/conceal.php:

return [
    /*
     * Array of keys that will be concealed automatically.
     */
    'defaults' => [
        'password',
        'password_confirmation',
    ]
];

Usage

Use the default configuration to conceal the password:

$data = [
    'username' => 'wouter',
    'password' => 'secret'
];

$output = conceal($data);
print_r($output);

// Outputs: ['username' => 'wouter', 'password' => '********']

Set keys on the fly:

$data = [
    'api_key' => 'secret'
];

$output = conceal($data, ['api_key']);
print_r($output);

// Outputs: ['api_key' => '********']

Everything works exactly the same for collections:

$data = new Collection([
    'username' => 'wouter',
    'password' => 'secret'
]);

$output = conceal($data);
print_r($output->toArray());

// Outputs: ['username' => 'wouter', 'password' => '********']

And last but not least, it works recursively too:

$data = [
    'password' => 'secret',
    'nextlevel' => [
        'password' => 'secret',
    ]
];

$output = conceal($data);
print_r($output);

// Outputs: ['password' => '********', 'nextlevel' => ['password' => '********']]

Facade

The examples above use the conceal() helper function. If Facades are more your thing you can use that instead:

use Kielabokkie\LaravelConceal\Facades\Concealer;

$data = [
    'password' => 'secret'
];

$output = Concealer::conceal($data);
print_r($output);

// Outputs: ['password' => '********']

laravel-conceal's People

Contributors

fusedreality avatar kielabokkie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-conceal's Issues

Check if key matches early

If a key matches one of the keys to conceal it should conceal the value straight away and not traverse the array or collection anymore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.