How to use htaccess/htpasswd with multiple users and logins - .htaccess

How do I add multiple users and login credentials such that multiple users can access a directory with their specific credentials? Let's say I want them all to be able to access the directory /about/team/
.htaccess:
AuthType Basic
AuthName "Please enter the username and password"
AuthBasicProvider file
AuthUserFile /path/.htpasswd1
Require user user1
AuthType Basic
AuthName "Please enter the username and password"
AuthBasicProvider file
AuthUserFile /path/.htpasswd2
Require user user2
AuthType Basic
AuthName "Please enter the username and password"
AuthBasicProvider file
AuthUserFile /path/.htpasswd3
Require user user3
.htpasswd
user1: 123%%^sample-passwordHJGH&^
user2: 456%%^sample-passwordHJGH&^
user3: 789%%^sample-passwordHJGH&^
Thanks

Specify a single auth block and use Require valid-user instead. For example:
AuthType Basic
AuthName "Please enter the username and password"
AuthBasicProvider file
AuthUserFile /absolute/file-path/to/.htpasswd
Require valid-user
Note that the file-path for AuthUserFile is an absolute filesystem-path.
Reference:
https://httpd.apache.org/docs/2.4/howto/auth.html#lettingmorethanonepersonin

Related

adding .htaccess and .htpasswd files do not restrict access to localhost folder

I have followed the procedure to the letter and it does not work for me.
The procedure: Create file .htaccess which has the following lines of text.
AuthType Basic
AuthName "restricted area"
AuthUserFile "C:/Apache24/htdocs/protected/.htpasswd"
require valid-user
Next create file .htpasswd which has a username and encrypted password created by http://www.htaccesstools.com/htpasswd-generator/
Next I insert both .ht files into the folder named protected, which is in the folder htdocs.
When I type in the browser address window http://localhost/protected/ and hit enter I get Index of protected and the list of files in it. It never asks for username or password.
See summary above.
AuthType Basic
AuthName "restricted area"
AuthUserFile "C:/Apache24/htdocs/protected/.htpasswd"
require valid-user

.htaccess/.htpasswd not working on web host

I have my website setup on a web host. My .htaccess and .htpasswd files are not working. The alert pops up but it keeps asking for the username and password even though I input the correct credentials.
The directory of these files is:
/home8/afmaclub/public_html/Members/.htaccess
/home8/afmaclub/public_html/Members/.htpasswd
The code for the .htaccess and .htpasswd is below:
.htaccess
AuthName "Member\'s Area"
AuthUserFile /home/afmaclub/public_html/Members/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
require valid-user
.htpasswd
Username:Encrypted Password

.htaccess password protect a file and a folder

My .htaccess currently contains this:
AuthUserFile /var/www/vhosts/mydomain.co.uk/httpdocs/.htpasswd
AuthName "Password Protected"
AuthType Basic
<Files "reports">
Require valid-user
</Files>
This password protects the "reports" page.
The credentials are stored in a .htpasswd file.
I now want to password protect the "admin" directory too.
I want a different username/password for this.
How do I password protect a directory? Also, how do I create a seperate username/password?
You could try using:
Require user <username>
Instead of:
Require valid-user
This will make it only accessible if you login with the name admin and it's apropiate password.
Sources: http://httpd.apache.org/docs/current/howto/auth.html#gettingitwr

.htaccess password on root not working

i'm trying to apply a site password to the root directory of my site:
www.example.com
I have my .htpasswd file in the same directory as the .htaccess file (public_html) and my .htaccess file has the following code:
AuthType Basic
AuthName "This Area is Password Protected"
AuthUserFile /public_html/.htpasswd
Require valid-user
With this code it prompts for credentials however when I enter the correct credentials it takes me to a server error page. Where have I gone wrong here?

htaccess different user permissions for different users

I can't seem to find the proper way to write my .htaccess file. I initially had the file set up to allow access to a directory of files and that worked fine:
AuthUserFile /var/www/html/technical/mep/.htpasswd
AuthGroupFile /dev/null
AuthName "Password Protected Area"
AuthType Basic
Require valid-user
Now what I need to do is add an additional htpasswd file (something like .htpasswd2) and allow those additional user to only be able to access a single file in that directory. How do I edit my current .htaccess file to make this happen?
You can simply use the <FilesMatch> container:
<FilesMatch protected.html>
AuthUserFile /var/www/html/technical/mep/.htpasswd2
AuthGroupFile /dev/null
AuthName "Password Protected Area 2"
AuthType Basic
Require valid-user
</FilesMatch>
And the file "protected.html" would use the .htpasswd2 file.

Resources