User authentication

User authentication is how Drupal knows which account is asking. Core checks a password at login, then recognizes the account by its session cookie.

Learn DrupalDrupal glossary

User authentication is how Drupal confirms which account sends a request. In core, a person submits a username and password to the login form, Drupal checks the password against the stored hash, and a session cookie identifies the account on later requests. Authentication answers who you are; permissions decide what you may do.

How it works in Drupal 11

The login form lives at /user/login and is built by UserLoginForm. The form calls the service user.auth, whose class UserAuthentication implements UserAuthenticationInterface. The method lookupAccount() finds the account by username, and authenticateAccount() compares the password with the stored hash. If the hash uses an outdated scheme, Drupal rehashes the password after a successful check and saves the account. The login form separately refuses blocked accounts with the message that the username has not been activated or is blocked.

Older code may call authenticate(), which returns a user ID. That method is deprecated since Drupal 10.3.0 and scheduled for removal in Drupal 12.0.0. New code should use the two methods above.

Failed logins are counted by flood control, the service user.flood_control. The shipped user.flood configuration sets user_limit: 5 with user_window: 21600, ip_limit: 50 with ip_window: 3600, and uid_only: false. Windows are in seconds. With uid_only off, the per-account count is kept per account and IP address.

After login, requests are recognized by an authentication provider. The provider with the ID cookie, registered as a global provider, reads the user ID from the session. It treats the request as anonymous when the account no longer exists or is blocked. Core also includes the HTTP Basic Authentication module, which provides a provider for the PHP_AUTH_USER and PHP_AUTH_PW values of a request. It counts its failed logins separately, with the same user.flood limits. A successfully identified visitor is authenticated; otherwise the visitor stays anonymous.

Example

An editor opens /user/login and keeps entering the wrong password. After five failures from the same IP address, Drupal answers that the account is temporarily blocked. A developer who needs access for testing can run drush user:login --name=anna, which generates a one-time login link for that username. Without options, the command targets user ID 1.

Common mistakes

  • Mixing up authentication and authorization. Logging in proves identity. It does not grant rights; roles do.
  • Assuming a second factor is built in. The core login checks a password only. Two-factor needs a contributed module.
  • Calling the deprecated method. Custom code that uses authenticate() will fail when Drupal 12 removes it.
  • Sharing the user 1 login. Shared credentials make the site log useless.

For marketing and content teams

You sign in at /user/login. If a login fails repeatedly, Drupal says the account is temporarily blocked; wait or use the password reset at /user/password instead of trying again. If your site holds customer data or can publish to the public, ask your developers about two-factor authentication for editors and administrators.

Sources

Questions about User authentication

Drupal's flood control counts failed logins. The shipped configuration in user.flood allows 5 failed attempts for one account from one IP address within 21,600 seconds (6 hours), and 50 per IP address within 3,600 seconds (1 hour). After that, Drupal refuses further tries. The message offers two options: try again later, or request a new password at /user/password.

The login flow in core checks a username and a password. For a second step, use a contributed module such as Two-factor Authentication (TFA), whose project page lists support for Drupal 10 and 11. Test it on a staging site first, and keep a recovery path for administrators.

Authentication proves who is asking: the login. Authorization decides what that account may do: roles and permissions. Drupal runs both on every request, and a correct password gives no rights beyond the roles of the account.

Related terms

All Drupal terms from A to Z