Authentication

Authentication is the process of determining whether someone or something is, in fact, who or what it says it is. Authentication technology provides access control for systems by checking to see if a user's credentials match the credentials in a database of authorized users or in a data authentication server.

Login

Use the login() method and pass the email and password to login.

Auth::login("hassan@email.com", "password");

you can use attempt() method to login by id.

Auth::attempt(1);

Check Authentication

use check() method to check if user login or no and check authentication.

Auth::check();

Retrieving The Authenticated User

Retrieving data of user.

Auth::user();

Logout

If user login, can logout by use logout() method.

Auth::logout();

Password

Can password verify and password hash in authentication.

use hash() method to password hash.

Auth::hash($pass);

and use verify() method to password verify.

Auth::hash($pass, $hash);

JWT

A JSON Web Token (JWT) is a JSON object that is defined safe way to represent a set of information between two parties.

Generate token

to generate token use token() method.

$token = Auth::token("hassan@gmail.com", "password");

and can use reToken() method to re generate token.

$token = Auth::reToken();

and can use updateToken() to update and generate new JWT token for user by only ID.

$token = Auth::updateToken(1);

JWT Authorization

JWT use "Authorization" HTTP header.

Authorization : Bearer $token

can use jwt() method to login.

$user = Auth::jwt();

you can login user by only ID when use jwtAttempt() method.

$user = Auth::jwtAttempt(1);

Last updated