htpasswd Generator
Create a bcrypt htpasswd line for Apache and nginx password protection. Hashed in your browser.
The hash is computed in your browser; the username and password are never sent anywhere.
What is an htpasswd file?
It makes the web server ask for a username and password (HTTP Basic Auth) before serving a folder. Each line is user:hash; only a hash of the password is stored, not the password. It is a quick way to lock down admin panels, staging sites or phpMyAdmin. Basic Auth sends the password with every request, so only use it over HTTPS.
Using it with nginx
Add the generated line to the file. The hash contains $, so wrap the line in single quotes, or the shell will treat it as a variable and break it:
echo 'user:$2y$10$...' | sudo tee -a /etc/nginx/.htpasswd
sudo chown root:www-data /etc/nginx/.htpasswd
sudo chmod 640 /etc/nginx/.htpasswd
sudo nginx -t && sudo systemctl reload nginx
Then protect the path in your server block:
location /admin/ {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
nginx does not hide a .htpasswd file in the web root on its own; keep the file under /etc/nginx/. nginx checks bcrypt through the operating system's crypt(): it works on distributions that use libxcrypt, such as Debian 11, Ubuntu 20.04, AlmaLinux and Rocky 8 and later. On old systems such as CentOS 7 the bcrypt line is not recognised and every login is refused.
Using it with Apache
Put this in the .htaccess file of the folder to protect, or in the virtual host:
AuthType Basic
AuthName "Restricted"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
AuthUserFile must be a full path and the file must live outside the web root (public_html, /var/www/html); inside it, a single misconfiguration can make it downloadable. With .htaccess, AllowOverride AuthConfig must be enabled for that folder. If the server has the htpasswd command, htpasswd -B -C 10 /etc/apache2/.htpasswd user writes the same kind of line straight into the file.
Why the $2y$ prefix?
Apache recognises bcrypt lines only with the $2a$ and $2y$ prefixes, and its own htpasswd command writes $2y$. The bcrypt library in the browser outputs $2b$; the computation is identical between these versions, so the tool switches the prefix to $2y$. libxcrypt, which nginx relies on, accepts $2y$ lines as well.
A full-access VDS is all you need to run nginx or Apache yourself; for the password itself, try our password generator.
More free tools
FAQ
About htpasswd Generator
bcrypt. It adds a random salt to every line and is slow on purpose; at cost 10 even a single guess takes milliseconds. {SHA} has no salt, a graphics card can try billions of guesses a second and the same password always gives the same hash. Only use SHA-1 for compatibility with an old system that lacks bcrypt.
No. The hash is computed in your browser; the username and password are not sent anywhere, not stored and never put in the address bar.
Check the server's error log first (/var/log/nginx/error.log for nginx). Common causes: the file path is wrong or the web server user cannot read the file, the line was echoed without single quotes so the $ parts were lost, or nginx runs on an old system without bcrypt support.