Basic Auth & Htpasswd Generator

Generate an HTTP Authorization: Basic header and an .htpasswd {SHA} entry locally in your browser.


    

    

How HTTP Basic Authentication & .htpasswd Work

HTTP Basic Authentication (defined in RFC 7617) is the simplest built-in mechanism for protecting staging sites, admin dashboards, metrics endpoints, and internal APIs directly at the web-server layer without touching application code. When a client sends a request, it includes an Authorization: Basic <token> header where the token is the Base64 encoding of username:password.

Using the Generated Outputs

  • Authorization Header: Paste the generated Authorization: Basic ... header into Postman, Insomnia, curl -H "Authorization: Basic ...", or automated smoke tests. Because Basic Auth transmits credentials in reversible Base64, always use it over HTTPS in production.
  • .htpasswd ({SHA}) Entry: Both Nginx (auth_basic_user_file) and Apache (AuthUserFile) support username:{SHA}<base64-sha1> lines. Everything in this tool is computed locally in your browser using the Web Crypto API (crypto.subtle.digest), so your passwords never leave your device.

Nginx & Apache Configuration Examples

In Nginx, save the generated .htpasswd line to /etc/nginx/.htpasswd (readable by the www-data or nginx user with chmod 640) and add the following inside a server or location block:

auth_basic "Restricted Area";
auth_basic_user_file /etc/nginx/.htpasswd;

In Apache, place a .htaccess file in the protected directory with AuthType Basic, AuthName "Restricted", AuthUserFile /path/to/.htpasswd, and Require valid-user.

Security Best Practices & FAQ

  • Is Base64 encryption? No. Anyone who intercepts the Authorization: Basic header can decode it immediately. Always enforce TLS/HTTPS and HSTS when using Basic Auth outside localhost.
  • Can I have multiple users in one .htpasswd file? Yes. Generate one line per user and place each entry on its own line in the .htpasswd file.
  • Why does this tool use {SHA} instead of bcrypt? {SHA} is natively supported across Nginx, Apache, and lightweight proxies (like Caddy or Traefik) and computes deterministically in pure browser Web Crypto without heavy WASM bundles. For high-security multi-user servers, you can also generate salted bcrypt hashes on the server with htpasswd -B.
  • How do I allow health checks without Basic Auth? In Nginx, wrap health-check locations in a separate location = /healthz { auth_basic off; } block so load balancers can probe your app without credentials.

Testing Your Configuration with curl

After reloading Nginx (nginx -t && systemctl reload nginx) or updating .htaccess, verify that unauthenticated requests return 401 Unauthorized with a WWW-Authenticate: Basic header, and that passing your generated header (curl -i -H "Authorization: Basic ..." https://example.com/) returns 200 OK. If you still see 403 Forbidden, double-check file permissions on the .htpasswd file so the web server worker user can read it.

Please read the privacy policy (agreement of the cookies usage, other websites embedded content, etc.). If you continue to use the site, we will assume that you agree with our privacy policy.
OkPrivacy Policy