HTTP Basic auth header
Runs in your browserCreate an Authorization: Basic header from user and password, or decode one back to user:password. With curl examples.
- Header
- Value only
- curl
- curl with header
Just Base64, no encryption
The browser joins user and password with a colon, encodes the result in Base64 and sends Authorization: Basic … with every request (RFC 7617). Anyone who sees the header has the password, so Basic auth is only acceptable over HTTPS. Example: Aladdin:open sesame becomes Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==.
Send Basic auth
curl -u 'user:password' https://api.example.com/ # or the header itself curl -H "Authorization: Basic $(printf '%s' 'user:password' | base64)" https://api.example.com/
fetch(url, { headers: { Authorization: "Basic " + btoa("user:password") } });
// Non-ASCII characters: encode as UTF-8 first
const b64 = btoa(String.fromCharCode(...new TextEncoder().encode("jörg:pässwort")));import requests
requests.get(url, auth=("user", "password"))$ctx = stream_context_create(['http' => ['header' => 'Authorization: Basic ' . base64_encode("$user:$pass")]]);# nginx, Apache, Traefik: protect a site with htpasswd instead of checking headers yourself. # See the htpasswd generator.
When the server says 401
echo user:pass | base64 encodes a line break too. Use printf '%s'.
The first colon separates user and password. Passwords may contain colons, usernames may not.
RFC 7617 recommends UTF-8, but some old servers expect Latin-1. The decoder tells you which one it found.
https://user:pass@host is deprecated and ends up in logs and browser history.
Questions about the basic auth header
Is HTTP Basic auth secure?
Only over HTTPS. The password is just Base64-encoded and sent with every request. For APIs prefer tokens that expire; for protecting a staging site Basic auth over HTTPS is fine.
How do I decode a Basic auth header?
Remove “Basic ”, decode the rest as Base64 and split at the first colon. The Decode tab does that and also handles a missing padding or Base64url characters.
Where do I set up Basic auth on the server?
With an htpasswd file for nginx, Apache or Traefik. The htpasswd generator writes the file and the config.