codetyme/laravel-temp-password 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

codetyme/laravel-temp-password

Composer 安装命令:

composer require codetyme/laravel-temp-password

包简介

A Laravel package to generate temporary passwords

README 文档

README

🔐 Laravel Temp Password

A Laravel package to generate one-time, time-limited temporary passwords for user authentication. These passwords can be used in place of regular passwords during login and automatically expire after a configurable period (e.g., 5 minutes).

🚀 Features

  • No need to modify your existing login logic
  • Supports default and custom user models
  • Auto-expires passwords (default: 5 minutes)
  • Optional CLI command to generate temporary passwords
  • Supports password strength levels: simple, medium, strong
  • Uses Laravel's built-in authentication system

📦 Installation

composer require codetyme/laravel-temp-password

📂 Publish Config & Migrations

php artisan vendor:publish --provider="codetyme\TempPassword\TempPassServiceProvider" --tag=config
php artisan migrate

This will:

  • Publish the config/temp-password.php file
  • Create the temp_passwords database table

⚙️ Configuration

Your published config file looks like this:

return [
    'enabled' => env('TEMP_PASS_ENABLED', true),

    'expiry_minutes' => env('TEMP_PASS_EXPIRY_TIME', 5), // Valid for 5 minutes

    'length' => env('TEMP_PASS_LENGTH', 8), // Default password length

    'strength' => env('TEMP_PASS_STRENGTH', 'medium'), // simple | medium | strong
];

You can override these settings in your .env file if needed:

TEMP_PASS_ENABLED=true
TEMP_PASS_EXPIRY_TIME=5
TEMP_PASS_LENGTH=10
TEMP_PASS_STRENGTH=strong

🧠 How It Works

Once installed, the package automatically hooks into Laravel’s default authentication.
No need to change Auth::attempt() or override any guards.

You can log in with either:

  • Regular user password
  • A one-time, time-limited temporary password

🔐 Usage

📌 Generate a Temp Password (Programmatically)

use codetyme\TempPassword\Facades\TempPass;

// Using default settings
$password = TempPass::generate($user);

// Custom length
$password = TempPass::generate($user, 12);

// Custom length + strength
$password = TempPass::generate($user, 16, 'strong');

🖥️ Generate via Artisan Command (Optional)

php artisan temp-password:generate

Options:

Option Description
--email User's email (required or prompted)
--model Fully qualified model class (optional)
--length Password length (optional)
--strength Password strength (optional)

Examples:

# Prompt for email and use default model (App\Models\User)
php artisan temp-password:generate

# Provide email directly
php artisan temp-password:generate --email=someone@example.com

# Use a custom model
php artisan temp-password:generate --email=someone@example.com --model=App\\Models\\Customer

# Use a custom length
php artisan temp-password:generate --email=someone@example.com --length=10

# Use a custom length + strength
php artisan temp-password:generate --email=someone@example.com --length=15 --strength=strong

🔧 Example Use in Tinker

php artisan tinker
$user = App\Models\User::first();
$password = TempPass::generate($user);

Auth::attempt(['email' => $user->email, 'password' => $password]); // returns true ✅

📁 Database Table

The package creates a temp_passwords table with the following structure:

Column Description
authenticatable_id ID of the user
authenticatable_type User model class (e.g. App\Models\User)
temp_password Bcrypt-hashed temp password
used Marked true after first use
created_at For expiry check

🛡️ Security Notes

  • Passwords are hashed using bcrypt before storing
  • Temp passwords are one-time use only
  • Expire automatically after the configured minutes

📚 Developer

Rohit Suthar, Mumbai Email: rohisuthar@gmail.com

📚 License

MIT License — open-source and free to use.

codetyme/laravel-temp-password 适用场景与选型建议

codetyme/laravel-temp-password 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 codetyme/laravel-temp-password 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codetyme/laravel-temp-password 我们能提供哪些服务?
定制开发 / 二次开发

基于 codetyme/laravel-temp-password 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-19