y-ui / laravel-data-masking
基于Laravel的MySQL数据脱敏工具
v1.0.4
2020-04-27 06:46 UTC
Requires
- php: >=7.0.0
- doctrine/dbal: ^2.5
Requires (Dev)
- php: >=7.0.0
README
安装
composer require --dev y-ui/laravel-data-masking ^1.0
配置
如果您使用的是Laravel 5.5或更高版本,则包将自动发现。
否则,您需要在您的 config/app.php
中手动配置它,并在提供者数组中添加以下内容
\Yui\DataMasking\DataMaskingServiceProvider::class,
用法
简单用法
1. 扫描数据库并生成配置文件 config/data-masking.php
php artisan data:scan
2. 编辑配置文件 data-masking.php
3. 执行
php artisan data:mask
选项
#Specify the name of the table to scan
php artisan data:scan --tables=users,orders
#Update only data that meets the criteria
php artisan data:mask --tables=users --where='id>100'
配置文件
您可以自定义任何字符
'name' => '' nothing to do
'name' => '*:1-' Tom => *** Replace all characters
'name' => '0:2-4' William => W000iam
'name' => '0:3-5' Tom => To000
'phone' => '*:4-7' 18666666666 => 186****6666
'phone' => '123:4-' 18666666666 => 18612312312
'phone' => '*:1~2' 18666666666 => 1********66 Keep the first and end character
'email' => 'email:3-' production@google.com => pr********@google.com Replace only the characters before @
'name' => 'text:Alex' everything => Alex Replace all value to text
您还可以使用faker来替换列
'address' => 'faker:address'
'date' => "faker:date($format = 'Y-m-d', $max = 'now')"
'name' => 'faker:name'
如果有一个字段的内容为0-9,您想将其全部设置为2
'cloumn_name' => '2:1-' //This is faster than using faker
Faker wiki https://github.com/fzaninotto/Faker
如果您想使用中文,打开 config/app.php
,添加 'faker_locale' => 'zh_CN'
,