PHP code example of laraditz / user-security

1. Go to this page and download the library: Download laraditz/user-security 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/ */

    

laraditz / user-security example snippets


'providers' => [
    ...
    Laraditz\UserSecurity\UserSecurityServiceProvider::class,
    ...
],

...
$app->register(Laraditz\UserSecurity\UserSecurityServiceProvider::class);
...

..
$app->withFacades(true, [
    ...
    Laraditz\UserSecurity\Facades\SecureUser::class => 'SecureUser'
]);
...



namespace App;

...
use Laraditz\UserSecurity\Traits\UserSecurable;

class User extends Model implements AuthenticatableContract, AuthorizableContract
{
    ...
    use UserSecurable;
    ...
}

...
'mnemonic' => 'The :attribute is invalid.',
'mnemonic_exists' => 'The :attribute is already been used.',
...

// to add/update security pin for eloquent user
$user->updateSecurityPin($security_pin);

// to add/update entropy for eloquent user
$user->updateEntropy($entropy);

// to add/update multiple authenticators
$user->updateMultipleAuthenticators(['security_pin' => $security_pin, 'mnemonic_entropy' => $entropy]);

// Success response

// using service container to generate mnemonic object
$mnemonic = app('SecureUser')->mnemonic()->generate();

// using alias to generate mnemonic object
$mnemonic = \SecureUser::mnemonic()->generate();

// Use mnemonic codes to find entropy
$mnemonic = \SecureUser::mnemonic()->words($words);

// Generate Mnemonic using specified Entropy
$mnemonic = \SecureUser::mnemonic()->entropy($entropy);

// Get user by mnemonic words
$user = \SecureUser::mnemonic()->userByWords($words);

$this->validate($request, [
    ...
    'mnemonic_words' => '.
]);

use Laraditz\UserSecurity\Rules\MatchSecurityPin;


$this->validate($request, [
    ...
    'security_pin' => new MatchSecurityPin,
    'security_pin2' => new MatchSecurityPin($model),
    ...
]);