# Logging In

## Login Checklist

{% hint style="info" %}
If you have recently upgraded to v2 of the elentra-developer environment, verify that your database hostname in `www-root/core/config/config.inc.php` is set to `mariadb.`
{% endhint %}

You can see the login page but receive a message stating that "An internal server error has occurred" or "The application credentials are incorrect for this system" every time you enter your login credentials.

![Usually this indicates a problem authenticating with the API ](/files/-M93w8YBLZAKI9PLGfsC)

![Elentra was able to connect to the database, but the application username or password are not correct](/files/-M93wBkrDGpYOQ7LSnqD)

{% hint style="info" %}
With v2 of the elentra-developer Docker environment you can now access phpMyAdmin from `http://localhost:3000` on your development machine.
{% endhint %}

### Can you login via API directly?

The login form utilizes the API to authenticate users. Using a tool like Postman to test logging in directly via API is a very good way to get clarity where the error actually is. Moreover, the API will provide a better response regarding what the actual issue is.&#x20;

* Open Postman, and create a `POST` request to `http://elentra-1x-me.localhost/api/v2/auth/login` while passing the following data in the `Body` \
  \
  `{` \
  &#x20;   `"username": "admin",` \
  &#x20;   `"password": "apple123",` \
  &#x20;   `"auth_username": "[Your AUTH Username]",` \
  &#x20;   `"auth_password": "[Your AUTH Password]",` \
  &#x20;   `"auth_method": "local",` \
  &#x20;   `"auth_app_id": 1` \
  `}`
* You should see helpful response identifying what the logging in issue is. If the response you receive isn't helpful, then please proceed with the checklist below.

### Database

* Database schema is created?
* Database user exists?
* Database user password is correct?
* Database user has permissions to the schema? (try with full permissions, to make sure that permissions aren’t the issue, restrict afterwards)
* Can you connect to the database with the MySQL command line (or a database GUI like phpMyAdmin) and view the tables of the database?
* Is the character encoding/collation correct for the database and the DEFAULT\_CHARSET in `settings.inc.php`? Mixing Latin1 and UTF8 can lead to problems. This may require adding debug statements or stepping through the login process, and checking variables/error messages.

### Application

Verify the following in `www-root/core/config/config.inc.php`:

* There is a row in `[auth_schema].registered_apps` where:
  1. `script_id` matches \[“auth\_username” in the config file]?
  2. `script_password` matches MD5(\[auth\_password]) in the config file?
* The `AUTH_APP_ID` defined in settings.inc.php is the same as `[auth_schema].registered_apps.id`? (Try putting `Log::info($app_auth_credentials);` after that variable is defined in the API’s `AuthController.php postLogin()` method to be sure.)

### API

* Is the API set up correctly (for a development environment, there may be a symbolic link in `www-root/core/library/vendor/elentrapackages`)? [Make sure that the link is pointing to a valid API directory](/technical/developers/troubleshooting/composer.md#symlinking-the-api).
* Is the API accessible? You should be able to go to `[website url]/api/v2` and see the message “Welcome to the Elentra API. Please see our documentation for assistance.”. You can also use [Postman](https://docs.elentra.org/api/developers/quickstart-guide/postman) to work directly with the API; that will often show additional information that may be helpful.
* Is there a `.htaccess` file in your `www-root` folder?
* If using different Elentra applications (i.e. Admissions, ME, CPD), is the API the correct version for the application version you are running? CPD may require a different API version from ME.

### User

* Is there a row in `[auth_schema].user_data` where:
  1. `username` matches the username in the login form?
  2. `password` matches the SHA1(login form password + salt from row)?
  3. `organisation_id` exists in `[auth_schema].organisations`?
  4. the `app_id` in `[auth_schema].organisations` matches the `app_id` in in `[auth_schema].registered_apps`?
* Is there a row in `[auth_schema].user_access` where:
  1. `user_id` matches the id field in `[auth_schema].user_data`?
  2. `app_id` matches the id in `[auth_schema].registered_apps`?
  3. `organisation_id` matches the id in `[auth_schema].user_data`?
  4. `account_active` is true?
  5. `access_starts` is before now?
  6. `access_expires` is after now (or 0)?
  7. `locked_out_until` is NULL?

### Organisation

* Is the “organisation\_id” set to the correct value in `settings.inc.php`?
* Do the “AUTH\_APP\_ID” and “AUTH\_APP\_IDS\_STRING” variables in `settings.inc.php` match the ID of a row in the `[auth_schema].registered_apps` table?
* Are there entries in in `[auth_schema].user_preferences` for the “organisation\_switcher” module that are pointing to the wrong `organisation_id`? These rows can safely be removed because they will be regenerated as needed (they determine which Organisation is the default for that user when logging in).
* In the in `[auth_schema].organisations` table, is the template for this organisation set to a `www-root/templates`directory that does not exist (e.g. if the DB has come from a live site that has a customized set of templates, and your development site doesn't have them)?

### Logs

Be sure to check the following logs if you cannot see any errors or warnings being printed to the screen.

* `www-root/core/storage/logs/api.log`
* `www-root/core/storage/logs/error_log`
* Apache logs (typically `/var/log/httpd/error_log or /var/log/httpd/ssl_error_log`)

{% hint style="warning" %}
If you are developing using a Docker container, ensure that you are checking the logs from inside the container, not the host operating system!
{% endhint %}

### Other Debugging Tips

* Enable Laravel debug messages (only for use in development) by running the following command from the root of your `elentra-1x-me` project.

  ```
  echo "APP_DEBUG=true" > www-root/core/library/vendor/elentrapackages/elentra-1x-api/.env
  ```


---

# 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://docs.elentra.org/technical/developers/troubleshooting/logging-in.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.
