# Authentication

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 !";
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://atomframework.gitbook.io/docs/configuration-1/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
