Questions tagged [.htpasswd]

.htpasswd is a flat-file used to store usernames and password for basic authentication of Apache HTTP Server.

.htpasswd is a flat-file used to store usernames and passwords for basic authentication on Apache HTTP Servers. The name of the file is given in the .htaccess configuration, and can be anything, but ".htpasswd" is the canonical name. The file name starts with a dot, because most Unix-like operating systems consider any file that begins with dot to be hidden.

This file is often maintained with the shell command htpasswd which can add, delete, and update users, and will properly encode the passwords for use (so they are easily checked, but cannot be reversed back to the original password).

The file consists of rows. Each row corresponds to a username and hashed password pair, separated with the colon. For example:

user:password

The hashed password is typically "UNIX crypt" style, encrypted in either MD5 or SHA1 as common alternatives.

Additional users can be added by using the htpasswd shell command or by appending new lines to the file. For example:

user1:password1
user2:password2

Resources available on the Apache HTTP server can be restricted to users listed in the files created by htpasswd.

See also

526 questions
5
votes
3 answers

How do I password protect resources in a ModX Website using htaccess and htpasswd?

We are trying to protect a couple of different resources in our ModX installation. The current .htaccess code is as follows (not including all of the ModX stuff) AuthName "Dialog prompt" AuthType Basic AuthUserFile…
4
votes
1 answer

Whitelisting IPs with .htaccess / .htpasswd

Using the following .htaccess, I am able to successfully limit access to users with the correct username/password and users from a specific IP address: AuthType Basic AuthName "Please enter your password" AuthUserFile /path/to/.htpasswd Require…
claviska
  • 12,410
  • 2
  • 27
  • 50
4
votes
4 answers

Is protecting a website directory with a .htaccess file secure?

I was wondering if protecting a web directory with an .htaccess file (with the .htpasswd file outside the public apache webroot) is a secure way to protect a directory (and its contents). Could someone explain the Do's and Don'ts of this kind of…
0plus1
  • 4,475
  • 12
  • 47
  • 89
4
votes
1 answer

Create new HTTP auth credentials using PHP instead of shell

I know that it's possible to add new HTTP auth credentials through this shell script: htpasswd -c .htpasswd testing Is it possible to achieve the same with a PHP script? I know I could use a regular PHP auth system, but that's not what I'm looking…
DriesOeyen
  • 483
  • 6
  • 13
4
votes
1 answer

.htpasswd without .htaccess

I would like to protect a web folder via .htpasswd. However, as the .htaccess file is under version control, I would prefer to not mess with it. Instead, I would like to have the configuration…
donquixote
  • 4,877
  • 3
  • 31
  • 54
4
votes
1 answer

Linux - HTPASSWD file too big? (more than 2000 users)

I got here a quite huge HTPASSWD file which stores the users and their encrypted passwords. This file is used to authenticate users using HTTP. I got more than 2000 entries (users) in this file. The size of that file is 116KB. Additionnaly, about…
Jonathan Rioux
  • 1,067
  • 2
  • 14
  • 30
4
votes
1 answer

Passing username and password in URL to a `htpasswd` protected domain, would it be encrypted?

I know you can input the Username, Password and Domain for a htpasswd protected URL using the following schema : http://$username:$password@$Domain eg : http://sam:1234@example.com But would this work for an HTTPS Domain ? And if so would the…
sam
  • 9,486
  • 36
  • 109
  • 160
4
votes
1 answer

How to protect a webpage with a password?

I have a web app with a setting page that I would like to protect with a password so that unless the password is correctly entered the user cannot change any of the settings.
ben
  • 135
  • 1
  • 1
  • 8
4
votes
1 answer

Can I use .htpasswd to secure a nonexistent directory (a virtual mod_rewrite directory)?

I use the front controller pattern and so all requests are routed through my index.php file. I'd like to secure the 'Admin' controller (accessible at mysite/admin/) with .htpasswd. Only problem is, 'admin' is not a directory but is just a…
aw crud
  • 8,791
  • 19
  • 71
  • 115
4
votes
1 answer

Nginx sucessfully password protects PHP files, but then prompts you to download them

In a previous question, I was trying to password protect my /admin/ and sub-folders directory using Nginx with .htpasswd and regex. That was done successfully, but now, after password authentication was completed, Nginx prompts to "download" php…
some1
  • 1,547
  • 8
  • 26
  • 45
4
votes
1 answer

.htaccess requests correct login twice with .htpasswd and wordpress

I use .htaccess to ask for credentials to access members only data. The .htaccess file is stored in one of the directories and protects everything in directories below it. The .htaccess file itself is very simple: AuthName "Members Area" AuthType…
Billy
  • 41
  • 2
4
votes
1 answer

how to get logged in user's name from .htpasswd?

I have a password protected directory with htaccess and htpasswd. My .htpasswd file looks like this: user1:passwordstring user2:passwordstring user3:passwordstring When any of the user login successfully into the directory is there anyway I can get…
Badal
  • 3,738
  • 4
  • 33
  • 60
4
votes
1 answer

Http basic auth with nginx on different port

I've got a website with a reverse front-end proxy in which my app listens on port 3000. I've got another app that sits on 3001 which is part of the same directory that serves the contents for the site on port 3000. What I want to do. Anyone going to…
bob_cobb
  • 2,229
  • 11
  • 49
  • 109
4
votes
1 answer

Using Errordocument 401 leads to blank page

My .htaccess looks like this: ErrorDocument 401 /error/401.html AuthType Basic AuthName "Password Protected Area" AuthUserFile /var/www/vhosts/funatodev.de/httpdocs/wordpress/.htpasswd AuthGroupFile /dev/null Require valid-user # BEGIN WordPress #…
Sebastian Starke
  • 5,198
  • 3
  • 24
  • 35
4
votes
0 answers

Is it possible to use HTTP basic authentication within an iframe?

I have a directory that uses htpasswd for authentication. The authentication works fine in a normal browser window but displays an "Authorization Required" error when the directory or any file within it are embedded using an iframe. Is it not…
Jonathan
  • 323
  • 2
  • 11