> For the complete documentation index, see [llms.txt](https://atomframework.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://atomframework.gitbook.io/docs/configuration-1/authentication.md).

# Authentication

Authentication Configuration

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

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

{% tabs %}
{% tab title="model" %}
The user model that will be used for authentication. The username and password checks will be done from this model.
{% endtab %}

{% tab title="username\_column" %}
Here you have to define the name of the column containing the user name.
{% endtab %}

{% tab title="password\_column" %}
Here you have to define the name of the column containing the user password.
{% endtab %}

{% tab title="is\_admin\_column" %}
Determines whether the table contains a column for privilege escalation.
{% endtab %}
{% endtabs %}

## 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:

```php
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:

```php
$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:

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

auth()->login($user);
```

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

## 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.

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