bluecloud/laravel-security-question
Composer 安装命令:
composer require bluecloud/laravel-security-question
包简介
Helpers for managing security questions within your Laravel project
README 文档
README
Laravel security questions helps you easily integration security question facility for your project
Installation
composer require bluecloud/laravel-security-question
Migrate Tables
Run the following command to create tables to enable saving security questions
php artisan migrate
Publish Config
The package allows you to publish a config file to change settings for the package. Run the command below and
select Bluecloud\SecurityQuestionHelpers\SecurityQuestionHelpersProvider. A configuration file will be created
at config/questions.php
php artisan vendor:publish
Load Questions
Run the following command
php artisan questions:migrate
Adding Trait to User
Add the HasSecurityQuestions trait to your App\Models\User model as indicated below.
use Bluecloud\SecurityQuestionHelpers\HasSecurityQuestions; class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable, HasSecurityQuestions; }
Add Question(s) for User
To add question(s) for a user, add the code below
$user = auth()->user(); $user->save_questions([ ["security_question_id" => 1, "answer" => "Blantyre, Malawi"] ]);
Checking Question Answer
To check a user's submitted answer against the saved answers, add the code below
$question = SecurityQuestion::find(1); $check = $user->check_answer($question, "Blantyre, Malawi");
Note: The questions will sync. If the question was already attached for the user, the new answer will update the existing record
Routes
To manage question, you can make use of preconfigured api endpoints
1. List Security Question
GET /security-questions
2. Create Security Question
POST /security-questions
{
"name": "Sample security question"
}
3. Delete Security Question
DELETE /security-question/{id}
Configuration
Change package settings
1. Default Questions
Navigate to config/questions.php and find default security questions. You may change if you please.
<?php return [ "seeds": [] ]
2. Strict Mode
By default, the package turns strict mode off. When strict mode is off, the package ignores case for the answers
and removes all whitespaces and special characters to ease the matching of user submitted answers. If you want the
answers to match exact case and whitespace, turn strict mode on in config/questions.php
'strict' => true,
3. Middleware
To protect /security-questions routes, and middleware in config/questions.php. For example to
add auth:sanctum for authentication:
'middleware' => ["auth:sanctum"]
Base Routes Path
To change the base routes path for /security-questions for example in config/questions.php change the
following line
'path' => 'api/questions',
License
Laravel Sanctum is open-sourced software licensed under the MIT license.
bluecloud/laravel-security-question 适用场景与选型建议
bluecloud/laravel-security-question 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 353 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bluecloud/laravel-security-question 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bluecloud/laravel-security-question 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 353
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-22