HTTP Basic auth header

Runs in your browser

Create 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
How it works

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==.

In your code

Send Basic auth

curl
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/
JavaScript
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")));
Python
import requests
requests.get(url, auth=("user", "password"))
PHP
$ctx = stream_context_create(['http' => ['header' => 'Authorization: Basic ' . base64_encode("$user:$pass")]]);
Server side
# nginx, Apache, Traefik: protect a site with htpasswd instead of checking headers yourself.
# See the htpasswd generator.
Common mistakes

When the server says 401

Newline in the Base64

echo user:pass | base64 encodes a line break too. Use printf '%s'.

Colon in the username

The first colon separates user and password. Passwords may contain colons, usernames may not.

Umlauts

RFC 7617 recommends UTF-8, but some old servers expect Latin-1. The decoder tells you which one it found.

Credentials in the URL

https://user:pass@host is deprecated and ends up in logs and browser history.

FAQ

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.

Searches the list of pages on this site. What you type stays in your browser.