.htpasswd generator

Create users and passwords for Apache or nginx basic auth – with bcrypt, a ready-made .htpasswd file and the matching config.
  • Free
  • No sign-up
  • Your data stays on your device

Passwords and hashes are computed only in your browser and are never transmitted.

The most secure option, like htpasswd -B. Apache 2.4 and later; nginx only if the system’s crypt() supports bcrypt.

10

Each step doubles the computing time – for attackers, but also for every login. 10 is a sensible default.


.htpasswd contents



            

Set up your server

Ideally, store the .htpasswd outside the web root and enter its absolute path here.

Please enter an absolute path, e.g. /var/www/.htpasswd. Apache and nginx resolve relative paths differently.

Apache (.htaccess or <Directory>)


                    

In an .htaccess file, the protection only works if AllowOverride AuthConfig is enabled.

nginx (server or location block)


                    

nginx relies on the system’s crypt() function: bcrypt only works if it supports it – as on current Linux distributions with libxcrypt or on FreeBSD, but often not on older systems. APR1 works everywhere. Reload nginx afterwards.

How it works

  1. Add users

    Enter a username and password or generate a secure password. Add more users with a single click.

  2. Choose an algorithm

    bcrypt is the most secure. For older nginx servers without bcrypt support, use APR1-MD5.

  3. Use the file and config

    Save the file as .htpasswd on your server and copy the snippet for Apache or nginx.

What are .htpasswd and basic auth for?

HTTP basic auth protects parts of a website with a username and password, without the application needing its own login. Typical uses are staging and test environments, admin directories and preview pages for clients.

The browser sends the credentials with every request, merely Base64-encoded rather than encrypted. That is why basic auth is only secure over HTTPS.

What a line looks like

Each line of the .htpasswd holds one user: the name, a colon and the password hash, e.g. admin:$2y$10$…. The password itself is not stored in the file. When someone logs in, the server hashes the entered password with the same salt and compares the results.

The start of the hash tells you the algorithm:

  • $2y$ – bcrypt; the number after it is the cost
  • $apr1$ – APR1-MD5, Apache’s own MD5 scheme
  • {SHA} – unsalted SHA-1

The algorithms compared

bcrypt is the best choice. It is deliberately slow: each cost step doubles the computing time – for attackers, but also for every login. A cost of 10 is a sensible default. Higher values are more secure but slow down every request, because basic auth checks the password on each one.

APR1-MD5 is understood by Apache and nginx on every system. However, it can be brute-forced many times faster than bcrypt, so it is mainly useful where bcrypt isn’t available.

SHA-1 uses no salt: identical passwords produce identical hashes, and weak passwords can be cracked quickly. Only use it if a legacy system supports nothing else.

Where to store it and common mistakes

Keep the .htpasswd outside the web root so nobody can download it, and reference it by its absolute path in your config.

  • Error 500: Usually the server can’t find the file, for example because of a relative or wrong path. Apache resolves relative paths from the ServerRoot, nginx from its configuration directory.
  • Wrong permissions: The web server user (e.g. www-data) must be able to read the file.
  • Protection has no effect: In an .htaccess file, the directives only work with AllowOverride AuthConfig.
  • No login prompt: The browser remembers your credentials. Use a private window for testing.

Frequently asked questions

Which algorithm should I choose?

Use bcrypt with a cost of 10. Only choose APR1-MD5 if your server doesn’t support bcrypt, such as an older nginx setup. SHA-1 is insecure and only meant for legacy systems.

Where should I put the .htpasswd file?

Outside the web root – for example /var/www/.htpasswd if the site lives in /var/www/html. Reference it by its absolute path in your config, and make sure the web server can read it.

Does bcrypt work with nginx?

nginx checks bcrypt hashes using the operating system’s crypt() function. Current Linux distributions with libxcrypt, Alpine and FreeBSD support bcrypt; older systems often don’t. APR1-MD5, on the other hand, works with nginx everywhere.

How do I log out of basic auth?

Basic auth has no logout: the browser keeps the credentials until it is closed. Close all browser windows or clear the saved credentials. For testing, a private window is the easiest option.

Is basic auth secure?

Over HTTPS and with a strong password, basic auth is fine for staging environments and internal areas. Without HTTPS, the credentials can be intercepted, since they are only Base64-encoded.

Can I add multiple users?

Yes. Each user goes on a separate line of the .htpasswd. Require valid-user lets in every user in the file, while Require user admin, for example, only allows specific ones.

Source code of this tool on GitHub Open source under GPL-3.0, to read and download.

Guides on this topic

Related tools