# POST /auth/login

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the auth group.

Exchange a name and password for a session token or a second-factor challenge

- Who may call it: anyone (no token needed)
- Answers: 200 OK

With no second factor enrolled, the response contains token, expires_at, and user. Session tokens carry all scopes except export. If security.require_second_factor_admins requires the administrator to enroll, the response also sets enrol_second_factor to true and the token has no scopes. It can access routes that require no scope, including enrollment.

With a second factor enrolled, the response sets second_factor to true and contains challenge, expires_at, and user with only name. Submit the challenge to POST /auth/login/second-factor within two minutes from the same client IP address. A session token is bound to the client IP address that opened the session. UrbeStack rejects and revokes the token if it is presented from another IP address. UrbeStack records up to 255 characters from User-Agent for the session list when the client sends it.

Malformed credentials, an unknown name, a wrong password, a suspended account, and a client IP address blocked by the login policy all return 401 with the message "Invalid credentials". UrbeStack checks the login policy before verifying the password. A request that passes those checks but lacks a client IP address returns 500.

After verifying the credentials, UrbeStack checks whether the license allows sign-ins. It may refresh a stale result and retries a previous license refusal. If sign-ins are blocked, the response is 402 with the reason and, when available, this server's IP address as seen by the license server. If the license server has never answered, the grace period is seven days from installation.

For a customer whose system password is missing, UrbeStack uses the verified password to set it for SFTP and shell access. UrbeStack also uses the verified password to upgrade an imported SHA-512 crypt hash. A successful hash upgrade revokes the account's existing tokens. Sign-in can continue if either update fails.

## As commands

- [urbestack-user-set](https://urbestack.com/docs/commands/urbestack-user-set.md): Updates an existing UrbeStack account.
- [urbestack-token-create](https://urbestack.com/docs/commands/urbestack-token-create.md): Creates a token for the active UrbeStack user named by --user.
- [urbestack-license-check](https://urbestack.com/docs/commands/urbestack-license-check.md): Contacts the license server, records the result and reports whether the UrbeStack web interface allows sign-ins.

## Request body

JSON, the type [LoginRequest](https://urbestack.com/docs/api/types/LoginRequest.md).

- `name` (Username, required): A username consists of lowercase letters, digits and underscores. For the user role, it also serves as the system account name.
- `password` (string, up to 128 characters, required)

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/auth/login" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "alice",
    "password": "Sup3r-Secret-Passphrase"
  }'
```

Response, 200 OK:

```
{
  "challenge": "text",
  "enrol_second_factor": true,
  "expires_at": "2026-09-16T10:15:00Z",
  "second_factor": true,
  "token": "ub_9f3c2a7e1b5d4082a6c1e7f0",
  "user": {
    "backups": true,
    "bandwidth_bytes": 1,
    "bandwidth_cut": true,
    "bandwidth_cut_at": "text",
    "bandwidth_limit_bytes": 1,
    "created_at": "2026-09-09T10:15:00Z",
    "customers": 1,
    "disk_limit_bytes": 1,
    "email": "alice@example.com",
    "home": "text",
    "id": 1,
    "move_state": "leaving",
    "name": "alice",
    "owner": "text",
    "owner_id": 1,
    "package": "basic",
    "package_backups": true,
    "package_id": 1,
    "package_shell": true,
    "role": "user",
    "second_factor": true,
    "shell": true,
    "status": "active",
    "system_password": true,
    "uid": 1
  }
}
```

## Errors

- 400: --name is required
- 400: <name> has an owner: move them to the administrator before changing their role
- 400: <name> is an administrator: administrators have no home, so nothing to back up
- 400: <name> is an administrator: administrators have no system account
- 400: <name> is an administrator: administrators have no system account, so no shell
- 400: A <kind> token needs the client's address
- 400: A plugin's token names its scopes
- 400: A session is opened by a panel user: name one with --actor
- 400: A session opened for a user is a session
- 400: Cannot demote or suspend the last active administrator
- 400: Domain name required
- 400: Domain name too long
- 400: Invalid <what>: expected a non-negative integer
- 400: Invalid IPv4 address
- 400: Invalid IPv6 address
- 400: Invalid boolean
- 400: Invalid domain name
- 400: Invalid email address
- 400: Invalid id
- 400: Invalid label: 1 to 64 printable ASCII characters
- 400: Invalid password hash
- 400: Invalid password: 8 to 128 printable characters
- 400: Invalid port
- 400: Invalid role: admin, user or reseller
- 400: Invalid setting key
- 400: Invalid status
- 400: Invalid system password hash
- 400: Invalid user agent: 1 to 255 printable ASCII characters
- 400: Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
- 400: Nothing to change
- 400: Only a customer has an owner: an administrator or a reseller is the administrator's own
- 400: The second factor can only be turned off here; a user enrols from their own page
- 400: Username '<value>' is reserved
- 401: Invalid credentials
- 401: The password is not the panel password
- 402: <s.reason><seen>
- 403: <opener.name> may not open the panel of <owner>
- 403: Only a customer's panel is opened: <owner> is an administrator
- 403: User '<owner>' is suspended
- 404: Setting '<key>' not found
- 404: User '
- 404: User '<name>' not found
- 409: <name> is on the package <p.name> of the reseller <p.owner>: change the package before the move
- 409: <name> owns <owned> 
- 409: <who> and its bandwidth for the month is used up: 
- 409: <who> and its disk is used up: 
- 409: The package <p.name> allows <limit> 
