Htpasswd Generator

Create .htpasswd user lines for password-protecting folders on Apache and Nginx.

Htpasswd Generator tool

Line for this user
.htpasswd file

Browsers save it as htpasswd.txt, because they do not allow names that start with a dot. Rename it to .htpasswd after uploading it to your server.

Apache .htaccess
AuthType Basic
AuthName "Restricted area"
AuthUserFile /full/path/to/.htpasswd
Require valid-user
Nginx
location /private/ {
    auth_basic "Restricted area";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

About the Htpasswd Generator

Protecting a staging site, an admin folder or a private download area with a username and password is quick with HTTP basic authentication. This htpasswd generator creates the user lines for an .htpasswd file, hashing each password with APR1-MD5 or SHA-1, the formats Apache and Nginx accept, and lets you add several users at once. Passwords are hashed in your browser and never sent anywhere. Basic authentication should always run over HTTPS, because the credentials travel with every request.

The default APR1-MD5 format is Apache's own salted, iterated MD5 scheme, accepted by Apache on every platform and by Nginx. SHA-1 is offered for systems that expect the {SHA} format, though it is unsalted and weaker. A new random salt is generated for every password, so two users with the same password still get different hashes.

The tool also shows a ready-to-use Apache .htaccess snippet and the matching Nginx configuration. Keep the .htpasswd file outside your public web folder when you can, and always serve protected areas over HTTPS, because basic authentication sends the password with every request. Everything is calculated in your browser.

To create strong passwords first, use the password generator. For other server configuration, try the .htaccess generator, and to check password quality, the password strength checker. The finished file can be copied or downloaded, ready to upload next to your site's configuration.

How to use the Htpasswd Generator

  1. Enter a username and passwordUse a strong password; the generator button can create one.
  2. Choose the formatAPR1-MD5 works with Apache and Nginx; SHA-1 for {SHA} systems.
  3. Add more usersPress Add user to put the line in the list, then repeat for others.
  4. Download the fileDownload .htpasswd and use the Apache or Nginx snippet to switch protection on.

Htpasswd Generator features

  • APR1-MD5 (Apache) hashes with random salt
  • SHA-1 {SHA} hashes
  • Multiple users in one file
  • Download a ready .htpasswd file
  • Apache .htaccess snippet
  • Nginx configuration snippet
  • Password generator
  • Nothing is uploaded

Common uses

  • Password-protecting a staging or test site
  • Locking an admin folder on shared hosting
  • Adding basic auth to Nginx locations
  • Protecting downloads for clients
  • Teaching how web server authentication works

Password-protecting sites in practice: staging sites for clients, keeping previews out of search, exceptions, office access and file permissions

By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

HTTP basic authentication puts a simple password prompt in front of a whole site or folder, which makes it ideal for staging sites, client previews, admin tools and private downloads. This guide works through protecting a staging site for a client, explains why a password is better than robots.txt for keeping previews out of search results, and covers exceptions for webhooks, password-free access from an office, file permissions and limits worth knowing.

A worked example: a client preview

A web designer builds a new site for a client on a staging address and wants the client to review it before launch. The designer creates an .htpasswd file with one user for the client and another for the designer, places the file outside the public folder and adds the protection to the staging site's configuration. The client receives the address and login by separate messages, and the live site is unaffected.

Keeping previews out of search

Staging sites often end up in search results, showing unfinished pages and creating duplicate content. A robots.txt rule does not reliably prevent this, because search engines can still index a blocked address they find linked elsewhere, even without crawling it. A password stops crawlers completely, since they receive an authorisation error instead of content, so nothing from the preview can be indexed.

Exceptions for webhooks and health checks

Some paths must stay open even on a protected staging site, such as payment webhook endpoints that providers call, or health checks used by monitoring services. In nginx, adding auth_basic off; inside the location block for that path removes the prompt for it alone. Keep such exceptions as narrow as possible, and protect them by other means, such as webhook signatures.

Office access without a password

Teams often want colleagues in the office to skip the prompt while everyone else must log in. In nginx, satisfy any; combined with allow for the office's public IP address, deny all; and the usual basic authentication lines lets requests through if either condition is met. This works only when the office has a fixed public IP address.

File permissions

The .htpasswd file must be readable by the web server but not by other users on the server. A common setting is 640, owner read and write, group read, with the web server's group. Keeping the file outside the web root means it cannot be downloaded even if a configuration mistake exposes other files.

Stronger hashes where supported

On Apache 2.4 and later, the command-line htpasswd tool can create bcrypt hashes with its -B option, which are much harder to crack than older formats. Nginx accepts the formats the server's system libraries support, which varies between Linux distributions. Where bcrypt works on both, it is the better choice for long-lived protected areas.

Limits of basic authentication

Browsers remember basic authentication details until they are closed, and there is no standard logout button, so it suits staging sites and internal tools better than customer accounts. It also has no built-in lockout after failed attempts. Rate limiting in the server, or a tool that blocks repeated failures, slows down password-guessing attempts.

Removing access

When a client project ends or a contractor leaves, delete their line from the .htpasswd file. In typical setups the change takes effect for new requests without restarting the server. Reviewing the file whenever a project changes hands keeps old accounts from lingering for years.

Common mistakes

  • Relying on robots.txt to hide staging sites from search.
  • Leaving the .htpasswd file inside the public web folder.
  • Sending the address and password together in one message.
  • Forgetting to remove users when access is no longer needed.

Related tools

To set file permissions, use Chmod Calculator. For crawler rules on live sites, try Robots.txt Generator, and to add protective headers, Security Headers Generator.

Personal logins rather than shared ones

Give each person their own username instead of sharing one login among a team. Access can then be removed for one person without changing everyone's password, and server logs show who visited. Shared logins tend to spread through chat messages and emails until nobody knows who still has access.

Logs show the user

Web server access logs record the username for authenticated requests, shown in nginx through the remote_user field. This gives a simple record of who reviewed a staging site and when, which helps when a client says they have not seen the latest changes.

HTTPS before the prompt

Make sure plain HTTP requests are redirected to HTTPS before any login prompt appears, so credentials are never sent unencrypted. In nginx, the server block listening on port 80 should only redirect to HTTPS, with authentication configured in the HTTPS server block. Testing the http address in a private window confirms the order is right.

Launch day

When a site goes live, make sure protection is removed from the production configuration while staging stays protected. A forgotten password prompt on a live site blocks customers and returns authorisation errors to search engines, which may then drop pages from results. Checking the live site in a private browser window right after launch catches the mistake.

Privacy

Hashes are generated in your browser. Usernames and passwords are not uploaded or stored.

Frequently asked questions

What is an .htpasswd file?

A plain text file with one line per user, in the form username:hashed-password. Apache and Nginx read it to check the username and password a browser sends for HTTP basic authentication.

Which hash format should I use?

APR1-MD5, the default here, is salted and iterated, and works on all Apache platforms and in Nginx. Apache also supports bcrypt via its own htpasswd tool, which is stronger; SHA-1 is unsalted and should only be used when required.

How do I protect a folder with Apache?

Upload the .htpasswd file, ideally outside the public folder, then put the .htaccess snippet shown here into the folder you want to protect, with the full server path to the password file.

How do I use it with Nginx?

Save the file on the server and add the auth_basic and auth_basic_user_file lines shown here to the server or location block, then reload Nginx.

Is basic authentication secure?

Only over HTTPS. The browser sends the username and password with every request in an easily decoded form, so without HTTPS anyone on the network could read them.

Why does the same password give a different hash each time?

APR1-MD5 adds a random salt, which is part of the hash. This prevents attackers from spotting users with the same password and from using precomputed tables. The server still verifies the password correctly.

Is my password uploaded?

No. Everything is calculated by code running in this page on your own device. Your text, files and keys are never uploaded, stored or logged, so it is safe to use with private data.

Can I add more than one user?

Yes. Each line of an .htpasswd file is one user. Add a line for every user and keep them all in the same file; the server looks up the username first and then checks the matching hashed password.