PHP code example of gusmanwidodo / auth-kit-credentials

1. Go to this page and download the library: Download gusmanwidodo/auth-kit-credentials 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/ */

    

gusmanwidodo / auth-kit-credentials example snippets


use Gusmanwidodo\AuthKitCredentials\CredentialManager;

$auth = app(CredentialManager::class);

// Register (email by default)
$auth->register('[email protected]', 'secret123');

// ...or with an explicit type
$auth->register('+628123456789', 'secret123', 'phone');
$auth->register('gusman', 'secret123', 'username');

// Login (throws InvalidCredentialsException on failure)
$credential = $auth->login('[email protected]', 'secret123');

// Forgot -> returns a plaintext token for YOU to deliver by email/SMS
// (only the hash is stored). Returns null for an unknown identifier.
$token = $auth->forgot('[email protected]');

// Reset with the token
$auth->reset('[email protected]', $token, 'newSecret123');

public function beforeHooks(): array
{
    return [
        'credentials.register' => function ($ctx) {
            $user = User::create(['email' => $ctx->get('identifier')]);
            $ctx->set('subject_type', User::class)->set('subject_id', $user->id);
        },
    ];
}

'identifier_types'        => ['email', 'phone', 'username'],
'default_identifier_type' => 'email',
'lowercase_types'         => ['email', 'username'],
'min_password_length'     => 8,
'reset_ttl'               => 3600, // seconds