1

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?

Mark
  • 167
  • 1
  • 3
  • 13

1 Answers1

1

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.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • Creating a password seems to work now. The only problem is that when I do create a new password it doesn't update the .htpasswd file. My path is: C:/Users/Mark/Desktop/access/.htpasswd Is this path wrong? The folder access is on my Desktop and the file .htpasswd is in the folder. – Mark Feb 16 '22 at 12:47