I'll write a detailed: WIN32 implementation of Apache user authentication (original) _php

Source: Internet
Author: User
Keywords user authentication original implementation specific detailed file Access User1

Implementation of Apache user authentication under Win32
I believe that there are many kinds of verification methods, and in the WIN32 environment, how to set the Apache user authentication is very few, the manual is also described in the UNIX and Linux environment configuration, like me in Win32 under the hard groping Apache people should be many, Based on my experience, I introduce how I can implement Apache's user authentication function in the WIN32 environment.

Method One: Implementing a directory in a single user way can only be accessed by one user or several users.
Assuming that the Apache Web root is d:/home, the corresponding URL is http://localhost/
If you want to make the D:/home/test directory accessible only by a user, the directory corresponding to the URL is http://localhost/test, you need to access the URL to pop up the validation dialog box.
The D:/users directory is used to store password files user.passwd

1. Making User password files
On the command line, first use the Apache Htpasswd.exe tool to generate a password file called the User.passwd,-c parameter represents the new file, no parameter means adding a user in the password file.
D:\APACHE\BIN>HTPASSWD-BC d:/users/user.passwd user1 123456
In this way, a d:/users/user.passwd password file is generated with a line of text user1: $apr 1$4s3.....$.su.8airdeymx7jkv2rt9/
A user1 user is added successfully, and if you want to add another user, add the user by appending:
D:\apache\bin>htpasswd-b d:/users/user.passwd user2 123456
D:\apache\bin>htpasswd-b d:/users/user.passwd User3 123456

Well, when you're finished adding users, you can start implementing user authentication.

2. Make access verification files. htaccess
Open Notepad and enter the following text:

AuthType Basic
AuthName "Www.home.net"
AuthUserFile d:/users/users.passwd
Require user User1

Then save As. htaccess, save the path to the directory you want to implement validation for: d:/home/test/, note the Save as type select "All Files", the file name is ". htaccess", otherwise the. htaccess file will not be generated.

Here, specify a user authentication settings is complete, in the browser to enter the address of the authentication directory http://localhost/test/, you will find the browser popup a dialog box asks you to enter the user name and password, you can only enter the user User1 and Passwords 12345 to go in , it is useless to enter other users such as User2,user3.

3, implementation of a certain number of users to specify a directory validation
For example, decide http://localhost/test/can be accessed by User1 and User3, User2 cannot access, then edit the d:/home/test/.htaccess file and put the last sentence:
Require user User1
Require user User1 User3
This enables http://localhost/test/to be accessed only by User1 and User2.

4, to achieve the validation of a directory for all legitimate users
For example, to decide that http://localhost/test/can be accessed by all users in the d:/users/user.passwd file, edit the d:/home/test/.htaccess file and replace the last sentence with the following:

Require Valid-user

Can be implemented in the USER.PASSWD user can access the http://localhost/test/, as long as the user name and password entered no error.

Method Two: Using group user mode to realize verification
To implement is also very simple, in method one, the user in the USER.PASSWD file group, set up user group files, and then specify the AuthGroupFile in the. htaccess file. Suppose that a lot of users have been added to USER.PASSWD (User1,user2,user3,user4,...)
1, the establishment of a user group file D:/users/user.group, the contents are as follows:

Manager:user1 User3
Game:user2 User4
Download:user5 User6 User7

In this case, the 7 users of User1 to User7 are divided into 3 groups in the User.group file: Manager,game,download.

2, to achieve a group of users can access http://localhost/test/
Edit the D:/home/test/.htaccess file with the following content:

AuthType Basic
AuthName "Www.home.net"
AuthUserFile d:/users/users.passwd
AuthGroupFile D:/users/user.group
Require group game

Then, http://localhost/test/can only be accessed by the user User2,user4 in the game group.

The above steps, for the familiar with the development of programming comrades, can do a graphical interface program to complete, it is more convenient.
At this point, Apache's simple validation in the WIN32 environment is realized. It seems and Linux under the same setup method, but I took a lot of detours to find out, ashamed ashamed ah.
There are several ways to implement Apache's verification approach, which is just one aspect.
  • 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.