htaccess file to set password protection for the site folder

Source: Internet
Author: User
Tags password protection
    1. AuthType Basic
    2. AuthName "Restricted area"
    3. authuserfile/full/path/to/passwordprotected/.htpasswd
    4. Require Valid-user
Copy Code

The first line of AuthType refers to the use of the authentication method, where we choose the general basic, to note that the Basic authentication method of transmission of the password process is not encrypted, the more secure way is digest, but Digest authentication method needs Mod_auth_ Digest module support, before using it is best to check if the server has been turned on the module, the second line of the AuthName record of the authentication name, will be displayed in the Authentication inquiry box, if there are multiple certifications, the certification name can let you know the current authentication of what the user name and password to enter, Unfortunately, the authentication name does not seem to support Chinese; the third line, enter the authentication file path that holds the user's password.

    1. username:123456
    2. username:654321
    3. users:12tir.zibwq3c
Copy Code

After creating the file, we need to inject the user name and password into this file, if you use the Linux or UNIX class operating system, you can use the HTPASSWD command, if you can ssh to your server, Then you can use HTPASSWD to manage the user name and password in the. htpasswd file, and if not, there are many online tools such as http://www.htaccesstools.com/htpasswd-generator/or http:// www.4webhelp.net/us/password.php) can help you build the password used in the. htpasswd file. or Build with PHP

    1. Password to is 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. ?>
Copy Code

Finally, test, create a new folder passwordprotected upload the good two files and the same test file test.php into the folder, upload the folder to the server root folder, if you are on the local test server, enter HTTP// localhost/passwordprotected/test.php the path, will pop up a certification inquiry box at this time?

You can see the configuration of the server by entering the appropriate account name and password. If the browser appears with a 500 error, it is likely that the AuthUserFile path setting is incorrect.

  • 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.