# Browser keeps asking for username and password (Basic auth prompt loop)

**Code:** `401` · **Category:** HTTP · **Seen on:** HTTP, Apache, Nginx

The login dialog reappears after entering credentials, because the server keeps answering 401.

## Meaning

Wrong credentials, a different realm or password file, `.htpasswd` unreadable by the web server, or the Authorization header being stripped by a proxy all cause the loop. Check the error log for "user not found" or "password mismatch", the `AuthUserFile` path and permissions, and that the header reaches the app.

## Common causes

- Wrong username or password
- `.htpasswd` missing or unreadable by the web server user
- Wrong `AuthUserFile` path
- Authorization header stripped by a proxy
- Password hash type unsupported (bcrypt/apr1 mismatch)

## Quick fix

1. Check the server error log for the exact reason
2. Recreate the entry: `htpasswd -B /etc/nginx/.htpasswd user`
3. Fix permissions so the web server can read the file

## Detailed fix by platform

### Linux

1. 

```bash
sudo htpasswd -B -c /etc/nginx/.htpasswd admin
sudo chmod 640 /etc/nginx/.htpasswd && sudo chown root:www-data /etc/nginx/.htpasswd
```


## How to diagnose

1. **Error log** — Which reason?
2. **htpasswd** — Readable?
3. **Header** — Reaches the app?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/http/401-basic-auth-prompt-loop)
