How To Close A Page With A Password

Table of contents:

How To Close A Page With A Password
How To Close A Page With A Password

Video: How To Close A Page With A Password

Video: How To Close A Page With A Password
Video: How To Make Login Form With Password Toggle In HTML CSS JS 2024, November
Anonim

If your site, like most websites on the network, is hosted on an Apache server, then the easiest way to password-protect some of its pages is to use the authorization mechanism built into this server through the htaccess file. In this case, you will not have to make any changes to the source codes of the pages and knowledge of any programming languages is also not required.

How to close a page with a password
How to close a page with a password

Instructions

Step 1

Move the pages that you want to password protect to a separate folder on the server. If the authorization system must operate for all pages of the site, then this step is not needed.

Step 2

Create a service file htaccess. This is a regular text file, so you can use any text editor to work with it. It should contain the directives for the server software: AuthType Basic

AuthName "Access to these pages requires authorization!"

AuthUserFile /usr/yourAccount/yourSite/.htpasswd

require valid-user The AuthType Basic directive on the first line activates the basic authorization mechanism. It is called "basic" because the password entered by the visitor is then transmitted from the browser to the server encrypted using the Base64 algorithm. The next directive (AuthName) contains the text that the visitor will see on the authorization form. You can replace it with another. The AuthUserFile directive specifies the full path to the file that will store user logins and passwords. The last directive (AuthUserFile) defines the authentication principle. The Valid-user value means that users whose logins are written to the file specified in the AuthUserFile directive can be allowed to the password-protected pages.

Step 3

Save the file with directives under the name.htaccess - note that it has no name, only the extension.

Step 4

Create a file with a list of logins and passwords to access protected pages. To do this, use the htpasswd.exe utility from the Apache server software. You can download it, for example, here - https://www.intrex.net/techsupp/htpasswd.exe. It works in the command line, so you first need to start the terminal - press the key combination WIN + R, type cmd and press Enter

Step 5

At a command prompt, type: htpasswd -cm.htpasswd UserOne The -cm modifier tells the utility to create a new file and use MD5 for encryption. If m in the modifier is replaced by d, then the DES encryption algorithm will be used, if s - then the SHA algorithm, and the p modifier will disable password encryption. UserOne is the username, enter the username you need instead. After you press the Enter key, the utility will ask you to enter a password for this user. If you need to add the next user, then run the utility again, but do not use the letter "c" in the modifier.

Step 6

Place the generated.htaccess and.htpasswd files on your website server. The.htaccess file must be saved in the same directory where the password-protected pages are, and the.htpasswd file must be placed in the place, the full path to which is specified in the AuthUserFile directive.

Recommended: