Authentication is any process by which you verify that someone is who they claim they are. Authorization is any process by which someone is allowed to be where they want to go or to have information that they want to have.
I will show here how to set up basic auth on the apache with windows.
Apache server ( That's it )
( In windows it might be difficult to setup the Apache alone. So instead use something ling xampp, wamp or laragon.)
( I personally use the postman, but you can use your preferable client)
- Enable the necessary modules in the Apache
- Create the password file
- Set the auth directives in the virtual host file.
- Verify basic auth.
Enable the necessary modules in the ApacheOpen the httpd.conf file in the apache's conf folder.
Enable the necessary modules to make the basic auth working.
|Enable the necessary modules
Restart the apache to make the modules active.
Create Password File
You need to create a password file before you can use it for the basic auth. To create a password file you have to use the htpasswd.exe( it comes with the apache itself. You can find it inside the bin folder of the Apache server )
|htpasswd.exe to create password file
Create a password using the htpasswd.exe
|create basic auth password file
verify that file has actually created.
|the password file
Set the auth directives in the virtual host file
Set the location to the URL you want to enable the basic auth on.
For example, if you want to secure the /login with basic auth then replace <location /> to <location /login>
To read more about location click here. Apache location
After updating the virtual host file reload the apache to make the basic auth working.
Verify basic auth.
I am using the postman to verify the basic auth.
In case of valid username and password, you will get the 200 HTTP response.
|postman 200 HTTP response
In case of invalid username and/or password, you will get the 200 HTTP response.
|postman 401 HTTP response
Hope you find it useful.
Have a nice Day !