cbenjafield/laravel-password-manager
最新稳定版本:v0.1.1
Composer 安装命令:
composer require cbenjafield/laravel-password-manager
包简介
A simple password manager package for Laravel.
README 文档
README
Laravel Password Manager
A really simple Laravel package to encrypt and decrypt passwords in storage.
Installation
Composer:
composer require cbenjafield/laravel-password-manager
After installation, publish the config:
php artisan vendor:publish --provider="Benjafield\LaravelPasswordManager\PasswordServiceProvider" --tag="config"
Add a 16 character long key to your .env file. Also, if you would like to change the passwords table name, you may specify that too.
PASSWORDS_KEY="Your 16 Character Long String Here" PASSWORDS_TABLE="optional_password_table_name"
If you would like to generate a key for the .env file, you can use the following Artisan command:
php artisan passwords:generate-key
You can then copy the generated key to your .env file.
Then, publish the database migrations:
php artisan vendor:publish --provider="Benjafield\LaravelPasswordManager\PasswordServiceProvider" --tag="migrations"
Run the migrations:
php artisan migrate
Usage
Encrypting a password
You can make use of dependency injection:
<?php namespace App\Http\Controllers; use Benjafield\LaravelPasswordManager\PasswordManager; use Illuminate\Http\Request; class PasswordController extends Controller { public function store(Request $request, PasswordManager $passwords) { $request->validate([ 'name' => ['required', 'string', 'max:255'], 'password' => ['required', 'string', 'max:255'], ]); $password = $passwords->encrypt($request->name, $request->password); // Call the save method to store the password in the database. $password->save(); return response($password->password, 201); } }
Or you can use the facade:
use Benjafield\LaravelPasswordManager\Facades\PasswordsFacade; $password = PasswordsFacade::encrypt($request->name, $request->password); // Call the save method to store the password in the database. $password->save();
Decrypting a password
To decrypt a password, you need to retrieve the dynamic key used to encrypt it in the first place.
use Benjafield\LaravelPasswordManager\PasswordManager; use Benjafield\LaravelPasswordManager\Password; public function show(int $id, PasswordManager $passwords) { // Retrieve the password from the database. $password = Password::findOrFail($id); // Decrypt the password back into the original string. $decrypted = $passwords->decrypt($password->dynamic, $password->password); }
Caveats
This package doesn't handle authentication or middlewares involved in protecting the encryption or decryption of passwords - you will need to handle this yourself.
Licence
The MIT Licence (MIT). Please refer to Licence File for more information.
统计信息
- 总下载量: 112
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-11
