Home > Blockchain >  Authentication with PHP 8.0-Password protecting files and folders with .htaccess and .htpasswd
Authentication with PHP 8.0-Password protecting files and folders with .htaccess and .htpasswd

Time:02-18

I'm trying to password protect certain folders and files in my Apache directory. I place the .htaccess file in the folder and when I go to that directory, the browser asks for Authentication.

I tried creating a password from the command-line with the command, htpasswd -c .htpasswd client. The client username already exists in my .htpasswd file, but it doesn't prompt me to generate a new password.

My .htaccess file looks like this:

AuthUserFile C:/Apache24/htdocs/PHPandMySQL-2020/.htpasswd
AuthType Basic
AuthName "My Protected Folder"
Require valid-user

and my .htpasswd looks like this:

client: f.i9PC3.AtcXE

The authentication works on the folder. But when I go to the command-line, and type: htpasswd -c .htpasswd client. It doesn't prompt me to generate a new password.

Can anyone give me a hand here?

CodePudding user response:

It says it doesn't recognize the command.

It doesn't prompt for the password because you're not actually running the command! The htpasswd.exe executable is normally installed in the bin subdirectory of the Apache installation. So, if it's located at C:\Apache24\bin\htpasswd.exe then you need to use the following at the command prompt in the appropriate directory.

> C:\Apache24\bin\htpasswd -c .htpasswd client

Or, navigate to the bin directory and pass the full path to the .htpasswd file on the command line.

Or, add the bin directory to the Windows PATH environment variable to avoid having to type the full file-path to the command.

  • Related