🗝️ How to Create an Apache .htpasswd File for Basic Auth

Generate an APR1-MD5 hashed .htpasswd file

Need a quick username/password lock on a staging server or internal tool? HTTP Basic Authentication is the fastest way to get there. This guide covers how Basic Auth works, the .htpasswd file format, and how to wire it into a real server config.

What HTTP Basic Authentication is

HTTP Basic Authentication is the simplest auth scheme defined by the HTTP protocol itself. When a server receives a request for a protected resource, it responds with 401 Unauthorized and a WWW-Authenticate: Basic header, and the browser pops up a username/password prompt. Every subsequent request then carries an Authorization: Basic base64(username:password) header. No session cookies or application code are required — access control lives entirely in the web server configuration.

The .htpasswd file and server configuration

A .htpasswd file is a plain text file with one line per user, in the form "username:hashed-password". Apache references this file from .htaccess or a server config block to enforce authentication, for example:

Nginx doesn't use .htaccess — instead you set auth_basic and auth_basic_user_file directly inside a server block. The file format is identical, so the same .htpasswd file works for both.

The APR1-MD5 hash format

Storing plaintext passwords in .htpasswd would be a bad idea, so the file stores a hash instead. APR1-MD5 (Apache's htpasswd -m option) is not plain MD5 — it's Apache's own variant of the crypt algorithm. The output looks like $apr1$salt$hash, for example $apr1$Rg9uS37e$vT8OZzXqM3.Dj7L2b1pXe.. $apr1$ identifies the algorithm, followed by a random salt, followed by the actual hash. Because a fresh random salt is generated each time, hashing the same password twice produces two different output strings — that's expected behavior, not a bug. Modern Apache also supports the stronger bcrypt (-B option), but APR1-MD5 remains the most widely used default.

Security caveats

Basic Auth must always be paired with HTTPS. The value sent in the Authorization header is only Base64-encoded, not encrypted — over a plain HTTP connection, anyone intercepting the traffic can recover the username and password instantly. APR1-MD5 also slows brute-force attempts somewhat through its iterated hashing, but it's not as strong as modern algorithms like bcrypt or scrypt, so it's better suited to temporary access restrictions than protecting a production login system.

Enter a username and password and you can generate an APR1-MD5 hashed .htpasswd line instantly with our free tool — the hash is computed entirely in your browser, so nothing gets sent to a server.

🗝️ Try it yourself with the tool

How to Create an Apache .htpasswd File for Basic Auth — Generate an APR1-MD5 hashed .htpasswd file

More guides

🔁
How to Find a Domain's IP Address
Find the real server IP a domain points to
🛰️
How to Check DNS Propagation (What Is TTL?)
Understand TTL and check propagation after a nameserver change
📡
The Easiest Way to Find Your IP Address
Public vs private IP, and how to check yours
📐
CIDR Notation and How to Calculate a Subnet Mask
Convert CIDR notation like /24 into a subnet mask
🩺
How to Check an SSL Certificate's Expiration Date
Check a certificate's expiry without opening a browser
🪪
Understanding JWT Structure and How to Decode It
The Header, Payload & Signature — explained
🔑
What Makes a Strong Password (and How to Generate One)
Length, character sets & entropy explained
🔐
What Is Base64 Encoding and When to Use It
Why it's used in email attachments & data URIs
📘
Using a JSON Formatter to Read API Responses
Turn minified JSON into something readable
🗓️
How to Convert a Unix Timestamp to a Date
Turn seconds-since-1970 into a readable date
🗃️
How to Format Messy SQL Queries
Break a one-line SQL statement into readable clauses
🎨
Converting Between HEX, RGB, and HSL Color Codes
The difference between the three formats
🔠
camelCase, snake_case & Other Naming Conventions
When to use each naming style
🆚
How to Compare Two Text Files (Diff Checker)
Quickly spot differences between two versions