Atom Framework
Go to Github
v1.0.0
v1.0.0
  • Installation
  • Getting Started
  • Configuration
    • Environment
    • Authentication
  • Basics
    • Routing
    • Middleware
    • Controllers
    • Models
    • Requests
    • Views
    • URL Generation
    • Session
  • Misc
    • Security
      • Encryption
      • Hashing
    • Storage
    • Moment
Propulsé par GitBook

© 2025 Licon Corp

Sur cette page
  • Login
  • Authentication Check

Cet article vous a-t-il été utile ?

  1. Configuration

Authentication

Authentication Configuration

The authentication configuration is set into the config/auth.json file. Here is an example of authentication configuration:

{
  "model": "User",
  "username_column": "username",
  "password_column": "password",
  "is_admin_column": false
}

The user model that will be used for authentication. The username and password checks will be done from this model.

Here you have to define the name of the column containing the user name.

Here you have to define the name of the column containing the user password.

Determines whether the table contains a column for privilege escalation.

Login

You have an auth() helper that allows you to perform various operations related to authentication.

There's two functions for login user. The first is:

auth()->attempt([$credentials]);

$credentials is an array that contains values ​​of type key => value, this array must contain the username and password required for the connection. Example:

$credentials = [
    'username' => 'johndoe@example.com',
    'password' => 'password1234'
];

auth()->attempt($credentials);

The password does not need to be encrypted, Atom will encrypt it automatically before login.

You also have the login() function. Unlike the attempt() function, the login() function takes as argument a model of the type defined in the configuration. So, in example you have this:

$user = User::find('id', 1);

auth()->login($user);

Both functions will return true if the login was successful and false otherwise.

Authentication Check

You will surely need to check if a user is connected. You can do this with the check() function. the function will return true if there is a logged user and false otherwise.

if (auth()->check()) {
    echo "You're logged in !";
} else {
    echo "You're not logged in !";
}

PrécédentEnvironmentSuivantRouting

Dernière mise à jour il y a 6 ans

Cet article vous a-t-il été utile ?