search
Homephp教程php手册我来写个详细的: Win32下具体实现Apache的用户验证(原创)

apache|原创

Win32下具体实现Apache的用户验证
相信大家采用的验证方法很多种,而在Win32环境下如何设置Apache用户验证的介绍很少,手册上介绍的也是Unix和linux环境下的配置,象我这样在win32下苦苦摸索Apache的人应该不少,我根据自己的经验介绍一下自己是如何在Win32环境下实现apache的用户验证功能的。

方法一:以单用户方式实现某目录只能由某个用户或几个用户访问。
假设Apache的web根目录为 d:/home,对应URL为 http://localhost/
如欲使d:/home/test目录只能由某用户访问,该目录对应URL为http://localhost/test,访问该URL时需要弹出验证对话框。
d:/users目录用来存放密码文件 user.passwd

1、制作用户密码文件
在命令行方式先用Apache自带的工具htpasswd.exe生成一个密码文件叫user.passwd,-c参数表示新建文件,无参数表示在该口令文件中以添加方式增加一个用户。
D:\apache\bin>htpasswd -bc d:/users/user.passwd user1 123456
这样,就生成了d:/users/user.passwd 口令文件,里面有一行文字 user1:$apr1$4S3.....$.su.8AIrDEYMX7jKv2RT9/
成功增加了一个user1的用户,如果想再添加其他用户,就采用追加方式添加用户:
D:\apache\bin>htpasswd -b d:/users/user.passwd user2 123456
D:\apache\bin>htpasswd -b d:/users/user.passwd user3 123456

好了,当添加完用户,就可以着手实现用户验证了。

2、制作访问验证文件 .htaccess
打开记事本,输入以下文字:

authtype basic
authname "www.home.net"
authuserfile d:/users/users.passwd
require user user1

然后另存为 .htaccess,保存路径为你想实现验证的目录:d:/home/test/下,注意保存类型选"所有文件",文件名为".htaccess",否则就不会生成 .htaccess 文件了。

到这里,指定某个用户验证的设置就完成了,在浏览器中输入验证目录所对应的地址 http://localhost/test/,会发现浏览器弹出一个对话框要求你输入用户名和口令,你就只能输入用户user1和密码12345才能进去,输入其他用户如user2,user3是没用的。

3、实现指定某几个用户对一个目录的验证
例如决定 http://localhost/test/ 能由user1和user3访问,user2不能访问,则编辑 d:/home/test/.htaccess 文件,把最后的一句:
require user user1
改为:
require user user1 user3
如此就实现了 http://localhost/test/ 只能由user1和user2访问

4、实现所有合法用户对一个目录的验证
例如决定 http://localhost/test/ 能由 d:/users/user.passwd 文件里的所有用户访问,则编辑 d:/home/test/.htaccess 文件,把最后的一句改为 :

require valid-user

就可以实现在 user.passwd 里用户都能访问http://localhost/test/了,只要输入的用户名和密码没有错误。

方法二:采用群组用户方式实现验证
要实现其实也很简单,在方法一中对 user.passwd 文件里的用户进行分组,建立用户组文件,再在 .htaccess 文件里指定 authgroupfile 就可以了。假设 user.passwd 中已经添加了很多用户 (user1,user2,user3,user4,...)
1、建立一个用户组文件 d:/users/user.group ,内容如下:

manager:user1 user3
game:user2 user4
download:user5 user6 user7

如此,user.group 文件里把 user1至user7这7个用户分为了3个组:manager,game,download 。

2、实现某组用户能访问 http://localhost/test/
编辑 d:/home/test/.htaccess 文件,内容如下:

authtype basic
authname "www.home.net"
authuserfile d:/users/users.passwd
authgroupfile d:/users/user.group
require group game

那么,http://localhost/test/就只能由 game组里的用户 user2,user4 才能访问了。

以上步骤,对于熟悉编程开发的同志来说,完全可以做个图形界面程序来完成,就省事多了。
至此,Apache在Win32环境下的简单验证就实现了。看来和 Linux下的设置方法差不多,我却走了不少弯路才摸索出来,惭愧惭愧啊。
实现Apache的验证方法还有数种途径,以上只是一方面而已。



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.