By default, a one-time password is a 6-digit number.
##Changing the password length
You can change the length of the password by setting the password_length
parameter in the one-time-passwords
config file.
##Changing the password format
One-time passwords are generated by the Spatie\LaravelOneTimePasswords\Support\PasswordGenerators\NumericOneTimePasswordGenerator
class.
You can change the password format by creating your own class that implements the Spatie\LaravelOneTimePasswords\Support\PasswordGenerator
interface.
Here's an example of a custom password generator that generates a 6-character alphanumeric password:
namespace App\Support;
use Spatie\LaravelOneTimePasswords\Support\PasswordGenerator;
class AlphanumericPasswordGenerator implements PasswordGenerator
{
public function generate(int $length): string
{
return bin2hex(random_bytes($length / 2));
}
}
Then, in your config/one-time-passwords.php
file, set the password_generator
key to your custom class:
return [
'password_generator' => App\Support\AlphanumericPasswordGenerator::class,
];