1. Go to this page and download the library: Download skywalker-labs/passwordless library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
skywalker-labs / passwordless example snippets
use Skywalker\Otp\Concerns\HasOtp;
class User extends Authenticatable
{
use HasOtp;
}
use Skywalker\Otp\Facades\Otp;
// Send an OTP to an email or phone
$otp = Otp::generate('[email protected]');
// Verify the submitted OTP
try {
Otp::verify('[email protected]', $request->otp);
} catch (\Skywalker\Otp\Exceptions\InvalidOtpException $e) {
// Invalid or expired OTP
}
use Skywalker\Otp\Domain\Contracts\OtpService;
public function __construct(private readonly OtpService $otp) {}
public function send(string $identifier): void
{
$this->otp->generate($identifier);
}
// Generate a signed link valid for 15 minutes (configurable via 'expiry')
$link = Otp::generateMagicLink('[email protected]');
// → https://your-app.com/magic-login?identifier=...&signature=...
// Route: GET /magic-login → passwordless.magic-login
// Validated automatically by hasValidSignature() in the controller
use Skywalker\Otp\Facades\Otp;
// Use a custom generator at runtime (e.g. alphanumeric, UUID-style)
Otp::useGenerator(fn() => strtoupper(substr(md5(microtime()), 0, 6)));
// In your EventServiceProvider or a Listener
use Skywalker\Otp\Events\OtpVerified;
use Skywalker\Otp\Events\OtpGenerated;
use Skywalker\Otp\Events\OtpFailed;
protected $listen = [
OtpVerified::class => [LogSuccessfulLogin::class],
OtpGenerated::class => [NotifySecurityTeam::class],
OtpFailed::class => [AlertOnRepeatedFailures::class],
];