Set password protection for the site folder in the htaccess file

Source: Internet
Author: User
Tags password protection
Set password protection for the site folder in the htaccess file

  1. AuthType Basic
  2. AuthName "restricted area"
  3. AuthUserFile/full/path/to/passwordprotected/. htpasswd
  4. Require valid-user

The AuthType in the first line refers to the authentication method used. Here we select general Basic. Note that the password transmission process in Basic authentication mode is not encrypted, the safer method is Digest, but the Digest Authentication method requires the support of the mod_auth_digest module. before using it, it is best to check whether the module has been enabled on the server; the authentication name recorded by the AuthName in the second line, it will be displayed in the authentication inquiry box. if there are multiple authentication, the authentication name will help you better understand the username and password for the current authentication. Unfortunately, the authentication name does not seem to support Chinese characters; line 3: enter the path of the authentication file that stores the user password.

  1. Username: 123456
  2. Username: 654321
  3. Users: 12tio. zIbWQ3c

After creating the file, we need to inject the user name and password to the file. if you use a Linux or Unix operating system, you can run the htpasswd command, if you can log on to your server through SSH, you can use htpasswd for management. user name and password in the htpasswd file, if not, there are a lot of online tools (such as http://www.htaccesstools.com/htpasswd-generator/ or http://www.4webhelp.net/us/password.php) can help you generate. the password used in the htpasswd file. Or use php to generate

  1. // Password to be encrypted for a. htpasswd file
  2. $ ClearTextPassword = 'some password ';
  3. // Encrypt password
  4. $ Password = crypt ($ clearTextPassword, base64_encode ($ clearTextPassword ));
  5. // Print encrypted password
  6. Echo $ password;
  7. ?>

Finally, test it. create a folder named passwordprotected to upload the two files and test the same test file. put php in this folder and upload the folder to the root folder of the server. if you are on the local test server, enter http: // localhost/passwordprotected/test. php path. will an authentication inquiry box pop up?

Enter the account name and password to view the server configuration. If a 500 error occurs in the browser, it is likely that the AuthUserFile path is incorrectly set.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.