How to use Apache HTACCESS to protect passwords _ PHP Tutorial

Source: Internet
Author: User
Tags http authentication password protection
Use Apache's HTACCESS to protect the password. Use Apache HTACCESS to protect the password. use Apache HTACCESS to protect the password in staging mode, you can use Apache HTACCESS to protect your website passwords.
Use Apache HTACCESS to protect passwords
In staging mode, if you want to make the specified directory on the website open to some people, you can use the password protection method for the website-using the htpasswd file.

The password file is used to store valid user names and password information for accessing the website/directory. Basically, Apache provides a program to create a password file, that is, the htpasswd program. In the bin directory after Apache installation, for example, after installing Apache in Windows, here:
  
  
  1. D:/Apache/bin/htpasswd.exe
The following describes how to create an htpasswd file.

Step 1: Create a. htpasswd file

First, you need to create a file named. htpasswd, which is used to store the user name and encrypted password.
For example, if the username is admin and the password is 123456, the content in the. htpasswd file may be like this:
  
  
  1. admin:9dKtKHPyz51Vs
Here, the user name is followed by the password, and the password is the encrypted ciphertext. Now you can upload the. htpasswd file to the root directory.

There is a website that generates the. htpasswd file online: http://www.htaccesstools.com/htpasswd-generator/


Step 2: Create a. htaccess file

Create a new. htaccess file and write the following content:
  
  
  1. AuthName "Restricted Area"
  2. AuthType Basic
  3. AuthUserFile /home/site/.htpasswd
  4. AuthGroupFile /dev/null
  5. require valid-user
Next, upload the. htaccess file and test whether the file can be accessed.

AuthName: the name of the pre-accessed region.
AuthType: indicates the authentication method used by HTTP. Basic indicates Basic HTTP authentication.
AuthUserFile: The. htpasswd file pointing to the root path of the server.
Require: only valid users in the file list can access the AuthName region.


Secret uses Apache's HTACCESS to protect the password in staging mode. if you want to make the specified directory on the website open to some people, you can use the password protection method for the website...

Related Article

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.