Basic Authentication with htaccess but without password file

.htaccessapache-2.2password

Can I use htaccess to restrict access to my site and specify the username/password within the .htaccess, so I don't have to worry about password files?

Best Answer

You can absolutely use .htaccess to restrict access, but I don't know of any way to avoid creating an equivalent .htpasswd file if you want to control access via users and passwords, rather than whitelisted IP addresses or similar.

Now, you can create any number of .htpasswd files; so if you wanted a specific one for a specific directory, that would be easy to set up by creating the .htpasswd file using:

htpasswd /usr/local/etc/apache/.your_htpasswd_filename_here username_here 

then specifying it using the "AuthUserFile" directive in your .htaccess file.

Related Topic