Skip to content

Instantly share code, notes, and snippets.

@BARNZ
Last active September 7, 2023 18:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BARNZ/b82fb3bdc1f27d6633dd85b0e6ae9fef to your computer and use it in GitHub Desktop.
Save BARNZ/b82fb3bdc1f27d6633dd85b0e6ae9fef to your computer and use it in GitHub Desktop.
Generate a Laravel 5.x hash/token
<?php
use Illuminate\Support\Facades\Password;
# Generate a token in the same style as laravels password reset tokens.
# Will generate something like: 785f616c4978a87ad65a899ed4133b358a4697649c55b0965a7ebb7486bd9801
/** @var DatabaseTokenRepository */
$repo = Password::getRepository();
$token = $repo->createNewToken($user);
# Laravels underlying token generation technique for the above is:
# hash_hmac('sha256', Str::random(40), <your-app-key>)
@sebastiansulinski
Copy link

You can also obtain it for a user using Password::broker()->createToken($user);

@AmrMonier
Copy link

You can also obtain it for a user using Password::broker()->createToken($user);

sorry if my questions seems weird but after creating this token how could i check which user dose it belong to ?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment