Skip to content

emka.web.id

writing knowledge, recording civilization

Menu
  • Home
  • Tutorial
  • Search
Menu

Butuh Fitur OTP di Aplikasi Laravel? Pakai Ini!

Posted on February 8, 2025

OTPZ adalah sebuah paket Laravel yang dibuat oleh Ben Bjurstrom (pembuat Prezet) yang menyediakan kata sandi sekali pakai (OTP) faktor pertama yang aman untuk aplikasi Laravel. Ini memungkinkan pengguna untuk memasukkan alamat email mereka dan menerima kode sekali pakai untuk masuk, sebagai ganti kata sandi.

Fitur Utama

  • Pembatasan Laju
  • Waktu kedaluwarsa yang dapat dikonfigurasi
  • Membatalkan OTP setelah penggunaan pertama
  • Mengunci OTP ke sesi pengguna
  • Membatalkan OTP setelah terlalu banyak percobaan gagal
  • Melihat pesan kesalahan yang detail
  • Kustomisasi templat email yang digunakan
  • Log yang dapat diaudit

Untuk pengaturan, instal paket melalui Composer:

Bash

composer require benbjurstrom/otpz

Kemudian publikasikan dan jalankan migrasi yang disertakan:

Bash

php artisan vendor:publish --tag="otpz-migrations"
php artisan migrate

Selanjutnya, tambahkan antarmuka dan trait paket ini ke model User Authenticatable Anda

PHP

<?php
// app/Models/User.php
namespace App\Models;

//...
use BenBjurstrom\Otpz\Models\Concerns\HasOtps;
use BenBjurstrom\Otpz\Models\Concerns\Otpable;

class User extends Authenticatable implements Otpable
{
    use HasFactory, Notifiable, HasOtps;

    // ...
}

Dan terakhir tambahkan rute yang disediakan oleh paket ini dalam file routes/web.php Anda:

PHP

Route::otpRoutes();

Secara opsional, Anda dapat mempublikasikan tampilan dan konfigurasi bawaan untuk lebih lanjut melakukan kustomisasi:

Bash

php artisan vendor:publish --tag="otpz-views"
php artisan vendor:publish --tag="otpz-config"

Paket ini bekerja dengan Laravel Breeze baik dengan Livewire maupun Inertia, dan petunjuk lebih lanjut disediakan tentang cara memperbarui metode LoginRequest::authenticate masing-masing dengan metode send email untuk menjalankan action SendOtp.

Jika Anda mencari cara cepat untuk memberikan pengguna akses yang aman dan sementara atau sekali pakai ke sistem, maka OTPZ mungkin adalah paket yang Anda cari.

Pelajari lebih lanjut tentang paket ini dan lihat kode sumbernya di GitHub.

Terbaru

  • Raspberry Pi OS: Why the November Update is a Win for Minimalism
  • React Can useState Hook Explained in 60 Seconds
  • How Do You Build an MMO Solo?
  • NixOS 26.11 “Zokor” Might Be the Most Practical Release for Desktop Power Users Yet
  • Why Your AWS Bill Can Just Tripled Overnight?
  • Why Indonesia’s Battle with Google is a Dangerous Game of Chicken
  • SYS010 Malware Explained: How Malvertising on Meta Bypasses MFA and Hijacks Your Digital Identity
  • Linux Mint 27 Adrien: Why This Version Jump is Make Sense?
  • NFS2ROOT: A 12-Year Reminder That Your Linux Kernel Is Never Truly Safe
  • The Death of Browsing and the Rise of the “Answer Engine Economy”
  • What’s new in Proxmox VE 9.3?
  • Why Your Morning Routine Needs an API: The Art of iOS Automation
  • Proof of Work is the New Certification: 5 AWS Projects to Build Before 2027
  • Omarchy is Our first agentic operating system
  • The Death of Popper.js: Why CSS Anchor Positioning is the New Standard for Connected UI
  • Why Your 2027 Cloud Career Depends on Moving Beyond Basic AWS Services
  • Why Discord is Ditching Electron for Rust: Is GPUi Actually the Future?
  • The End of the KDE Era: Why KaOS 2026.11 Is a Bold, Dangerous Gamble
  • The $2 Billion Code: Why GTA 6 is a Technical Miracle and a Hardware Nightmare
  • LibreDB Studio Explained
  • PHP 8.6 Is Officially Out: What’s New, What Breaks, and How We’re Upgrading
  • Rewriting Legacy Apps: 4 Data Migration Strategies That Actually Work
  • How to Install Clean Windows 11 Without Any Bloatware (Step-by-Step Guide)
  • IP Address Rate Limiting is Flawed—Here is the Right Way to Do It
  • Are Fedora 45 Stuck in Its Comfort Zone? A Short Review
  • Hacktober Recap 2026, A Month Full of Dangerous CVE: eMudhra, Gitlab, Brotli, PHP, NodeJS etc
  • 7 Skill Keamanan Jaringan yang Membuat Network Engineer Makin Dibutuhkan
  • How to Spin Up Disposable macOS and Linux VMs on Apple Silicon with TartVM
  • Belajar Cyber Security dari Nol hingga Siap Kerja, Ini Roadmap Lengkapnya
  • Running Windows 11 on Apple Silicon: UTM vs. Parallels Desktop vs. VMware Fusion
  • Canonical: Ubuntu coming soon to Snapdragon X2 Series platforms
  • Finally, wolfSSL adds post-quantum algorithms!
  • How to Run Gemma Embedding Models Using Docker
  • Deploy Nginx Rootful Container with Podman
  • How to Sandboxing Browser on Linux Desktop with Flatpak
  • Your MCP Server Is a Search Result Now
  • AI Roadmap: How To Become An Agentic Operations Manager In 2027
  • What Does a Machine Learning Data Scientist Do?
  • How To Use T3 Code
  • Is AGENTS.md always faster? Nope!

©2026 emka.web.id | Design: Newspaperly WordPress Theme