PHP code example of juststeveking / password-generator
1. Go to this page and download the library: Download juststeveking/password-generator 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/ */
juststeveking / password-generator example snippets
use JustSteveKing\PasswordGenerator\Facades\Generator;
// Generate a standard password
$password = Generator::generate(); // example 'strong-car-fast-snail'
// Generate a "secure" password
$password = Generator::generateSecure(); // example 'str0ng-c4r-f4st-sn41l'
use JustSteveKing\PasswordGenerator\Contracts\GeneratorContract;
use Illuminate\Http\JsonResponse;
class GeneratePasswordController
{
public function __construct(
private readonly GeneratorContract $generator,
) {}
public function __invoke(): JsonResponse
{
return new JsonResponse(
data: [
'password' => $this->generator->generate(), // or generateSecure() for "secure" passwords.
],
);
}
}
// Once you have added this to your container, and injected
$password = $this->generator->generate();
// Or like the Laravel implementation, generate a secure password
$password = $this->generator->generateSecure();