承接 cbenjafield/laravel-password-manager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Laravel Password Manager

Packagist Version Packagist License Build Status

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固