在htaccess 中,我想这么写AuthType Basic
AuthName "ABC-Group"
AuthUserFile /usr/www/CCC/public_html/nopublic/.htpasswd
require user zhangsan
我想设的密码是abcde
请问在htpasswd中我该怎么写?谢谢。

解决方案 »

  1.   

    這個是apache的內容吧網上抄一個給你
    http://motus.blog.51cto.com/78324/99192前些天在网上溜达,遇到一个网站需要口令才能登录,我很感兴趣.故又去翻APACHE的文档了解下,终于我也弄出一个需要口令认证的网站,故写下笔记分享下~
     
    APACHE的安装就另搜索吧,不在此再写了.下面来看下HTTPD.CONF文档,默认的文档里有这么一段话
    ------------------------------------------------------------------------------------------------------------------------
    .......
    # Each directory to which Apache has access can be configured with respect 
    # to which services and features are allowed and/or disabled in that 
    # directory (and its subdirectories). 

    # First, we configure the "default" to be a very restrictive set of 
    # features.  

    <Directory /> 
        Options FollowSymLinks 
        AllowOverride None 
        Order deny,allow 
        Deny from all 
    </Directory>
    ......
    -----------------------------------------------------------------------------------------------------------------------------
    其中有一行: 
        AllowOverride None
    AllowOverride为何物?有何用?下面我们来看下官方文档的解释:
    AllowOverride 指令 
    说明      确定允许存在于.htaccess文件中的指令类型 
    语法      AllowOverride All|None|directive-type [directive-type] ... 
    默认值    AllowOverride All 
    作用域    directory 
    状态      核心(C) 
    模块      core
    .htaccess文件(或者"分布式配置文件")提供了针对每个目录改变配置的方法,即在一个特定的目录中放置一个包含指令的文件,其中的指令作用于此目录及其所有子目录。
     
    OK,也就是说,可以在某一目录下配置.htaccess文件,然后通过AllowOverride 开关,我们就可以创建一个口令认证的网站了
    这里我以网站的根目录为例,如下
    <Directory /> 
        AllowOverride all                      //启用.htaccess 
        AuthType Basic                        //Basic认证方法,明文传送 
        AuthName "my web"                 //服务器标识 
        AuthUserFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/passwds"               //密码文件 
        Require valid-user                    //允许所有用户访问 
    </Directory>
    下面要配置密码文件C:/Program Files/Apache Software Foundation/Apache2.2/conf/passwds
    这个文档可通过记事本录入,格式为[username]:[password];也可通过bin下的一个htpasswd.exe小程序生成的,可支持MD5,CRYPT和SHA三种方式加密.下面就用htpasswd.exe创建一个帐号C:\Program Files\Apache Software Foundation\Apache2.2\bin\htpasswd.exe -c "C:/Program Files/Apache Software Foundation/Apache2.2/conf/passwds" motu 
    Automatically using MD5 format. 
    New password: *** 
    Re-type new password: *** 
    Adding password for user motu
    //创建C:/Program Files/Apache Software Foundation/Apache2.2/conf/passwds文档,用户名是motu,默认启用MD5加密.
    当你需要创建第二个用户时,只要将"-c"参数去掉就行了,否则就会删除之前的信息.
      

  2.   

    不是,这是我的php里面的
    我只想对nopublic目录加密。
    bin里面什么也没有
      

  3.   

    搞定了htpasswd -c /usr/www/CCC/public_html/nopublic/.htpasswd zhangsan谢谢大家