.htpasswd generator
- Free
- No sign-up
- Your data stays on your device
Passwords and hashes are computed only in your browser and are never transmitted.
.htpasswd contents
Set up your server
Ideally, store the .htpasswd outside the web root and enter its absolute path here.
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.
Check whether a password matches an existing entry. Supported are bcrypt ($2y$, $2b$, $2a$), APR1-MD5, MD5-crypt and SHA-1.
How it works
-
Add users
Enter a username and password or generate a secure password. Add more users with a single click.
-
Choose an algorithm
bcrypt is the most secure. For older nginx servers without bcrypt support, use APR1-MD5.
-
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
- Password Generator Generate strong passwords and passphrases for free – right in your browser, nothing is transmitted.
- Hash Generator Calculate MD5, SHA-1, SHA-256, SHA-512 and CRC32 hashes for text and files, create HMACs and verify checksums – no upload.
- Redirect Generator Generate 301 redirects for .htaccess or nginx – checked for loops, chains and duplicates.