Assuming you create the password using the following command and "myPassword" as the password
  htpasswd -c /usr/local/apache/passwd/passwords username

  This will create a file that looks like
  username:$apr1$sr15veBe$cwxJZHTVLHBkZKUoTHV.k.

  The $apr1$ is the hashing method, sr15veBe is the salt, and the last string is the hashed password. You can validate it using openssl using
  openssl passwd -apr1 -salt sr15veBe myPassword

  which will output
  $apr1$sr15veBe$cwxJZHTVLHBkZKUoTHV.k.

  A pipeline which you could use would be:
  username="something"
htpasswd -c /usr/local/apache/passwd/passwords $username
****Enter password:****

salt=$($(cat passwords | cut -d$ -f3)
password=$(openssl passwd -apr1 -salt $salt)
****Enter password:****

grep -q $username:$password passwords
if [ $? -eq 0 ]
then echo "password is valid"
else
echo "password is invalid"
fi
You may need to change your openssl command, as Apache's htpasswd command crypts slightly differently on each system.

htpasswd 是apache的小工具,在apache安装目录bin下可找到。

Usage:
htpasswd [-cmdpsD] passwordfile username
htpasswd -b[cmdpsD] passwordfile username password htpasswd -n[mdps] username
htpasswd -nb[mdps] username password
-c 创建一个新的加密密码文件
-n 不更新文件,显示结果
-m 使用MD5加密密码
-d 使用CRYPT加密密码(默认)
-p 不加密密码
-s 使用SHA加密密码
-b 直接在命令行输入密码,而不是提示后再输入密码
-D 删除用户
在Windows, NetWare与 TPF系统,'-m' 是默认的密码加密方式。
在所有其他系统,'-p'可能不能使用。

1.生成加密密码文件

htpasswd -c .pass fdipzone
New password:
Re-type new password:
Adding password for user fdipzone

这样就生成了一个使用CRYPT加密密码的文件

以下命令可以生成用md5加密密码的文件,b参数的作用是在命令行直接把密码输入,这样就不需要等提示输入密码再输入了。

htpasswd -cmb .pass fdipzone
Adding password for user fdipzone

2.修改密码

htpasswd .pass fdipzone
New password:
Re-type new password:
Updating password for user fdipzone

3.增加用户

htpasswd .pass guest
New password:
Re-type new password:
Adding password for user guest

4.删除用户

htpasswd -D .pass guest
Deleting password for user guest

如果使用p参数,不加密密码,系统会提示Warning,因此为了安全最好不要使用p参数。

htpasswd -cp .pass fdipzone
Warning: storing passwords as plain text might just not work on this platform.

.htaccess 调用加密密码文件控制访问权限

首先 Allowoverride 需要设置为 AuthConfig 或 All

然后在需要控制访问的目录下增加.htaccess

.htaccess内容如下

当访问该目录下的文件时,则会弹出要求输入用户名和密码的输入框。输入正确的用户名和密码后就能正常访问。

tips:为了安全,加密的密码文件请不要放在线上用户可以访问的路径。

OpenSSL命令---passwd

用途:

passwd命令计算一个密钥的哈希值或者计算列表中的每个密钥的hash值。

用法:

openssl passwd [-crypt] [-] [-apr1] [-salt  string] [-in file] [-stdin] [-noverify] [-quiet] [-table] {password}

选项说明:

-crypt:生成标准的unix口令密文。默认选项。

-1:用MD5基于BSD的密钥算法。

-apr1:Apache md5口令密文。

-salt  string:用指定的字符串填充。当从终端读取一个密钥时,则填充它。

-in file:从指定的文件中读取密钥。

-stdin:从stdin中读取密钥。

-noverify:当从终端读取口令时不去验证它。

-quiet:当命令行提供的密钥是缩短了的,则不输出警告。

-table:用户输入的口令和结果用缩进隔开。

password:需要处理的密钥值。

实例:

openssl passwd -crypt -salt xx password  

打印出xxj31ZMTZzkVA。

openssl passwd - -salt xxxxxxxx password

打印出($1$xxxxxxxx$UYCIxa628.9qXjpQCjM4a.)。

openssl passwd -apr1 -salt xxxxxxxx password

打印出<$apr1$xxxxxxxx$dxHfLAsjHkDRmG83UXe8K0。

https://zhidao.baidu.com/question/372107922550340204.html

http://blog.csdn.net/fdipzone/article/details/41020045

http://blog.csdn.net/as3luyuan123/article/details/14917959

Apache Htpasswd生成和验证密码的更多相关文章

  1. 使用apache htpasswd生成加密的password文件,并使用.htaccess控制文件夹訪问

    htpasswd 是apache的小工具.在apache安装文件夹bin下可找到. Usage: htpasswd [-cmdpsD] passwordfile username htpasswd - ...

  2. apache htpasswd.exe创建密码

    一.使用apache htpasswd.exe创建密码文件,命令请看PHP推荐教程:apache htpasswd命令用法详解 apache htpasswd命令用法实例 1.如何利用htpasswd ...

  3. wordpress密码生成与登录密码验证

    一.研究wordpress时wordpess的密码密码生成与登录密码验证方式很重要 WordPress密码已成为整合的首要目标,如何征服整合,就得了解WordPress密码算法. WordPress系 ...

  4. 使用htpasswd实现Nginx验证访问

    Nginx是一个高性能的WEB服务器,越来越多的用户使用,如果您的某个站点不希望对外公开(比如PHPMyAdmin),可以使用htpasswd实现Nginx验证访问. 安装htpasswd htpas ...

  5. (6) openssl passwd(生成加密的密码)

    该伪命令用于生成加密的密码 [root@docker121 ssl]# man -f passwd passwd (1) - update user's authentication tokens p ...

  6. 《Apache服务用户身份验证管理》RHEL6.3

    1.安装apache软件包 Yum install httpd 2.启动apache服务 /etc/init.d/httpd restart 3.创建一个目录,内编辑一个index.html文件 4. ...

  7. Java下使用Apache POI生成具有三级联动下拉列表的Excel文档

    使用Apache POI生成具有三级联动下拉列表的Excel文档: 具体效果图与代码如下文. 先上效果图: 开始贴代码,代码中部分测试数据不影响功能. 第一部分(核心业务处理): 此部分包含几个方面: ...

  8. 使用truelicense实现用于JAVA工程license机制(包括license生成和验证)

    开发的软件产品在交付使用的时候,往往会授权一段时间的试用期,这个时候license就派上用场了.不同于在代码中直接加上时间约束,需要重新授权的时候使用license可以避免修改源码,改动部署,授权方直 ...

  9. javascript中怎样验证密码是否含有特殊符号、数字、大小写字母,长度是否大于6小于12

    今天在温习了一下以前学过的知识,一般常用验证密码是通过正则表达式或是通过ASCII 一.用AscII码来验证

随机推荐

  1. 转载:ensemble计划和数据库

    原文来源:x2yline在生信进化树上的评论,http://www.biotrainee.com/thread-626-1-1.html Ensemble( ensembl.org网站是常用真核生物参 ...

  2. Go 语言defer用法

    defer延迟调用: 1.确保调用在函数结束时发生: 2.defer列表为先进后出: 3.通常在Open/Close  Lock/Unlock中使用. defer调用顺序示例: package mai ...

  3. JDBC的一些代码

    import java.sql.*; public class jdbc { //JDBC 驱动名及数据库名 URL static final String JDBC_DRIVE = "co ...

  4. SCOI2017酱油记

    Day0: 虽然是8点30开始模拟赛,还是设了个7点的闹钟调节生物钟.结果硬生生睡到7点40... 打开题目:T1期望,直接弃掉(到现在都不会期望已经可以滚粗了..) T2一眼可做,恩,先写个暴力.然 ...

  5. 查找文件【TLCL】

    locate locate 执行快速的路径名数据库搜索,输出每个与指定子字符串相匹配的路径名. locate bin/zip locate 命令的数据库是updatedb命令创建的. find loc ...

  6. 简介web服务器的工作原理

    一 什么是web服务器,应用服务器和web容器? 对于web服务器与应用服务器:“在过去它们是有区别的,但是这两个不同的分类慢慢地合并了,而如今在大多在情况下和使用中可以把它们看成一个整体.” 但是当 ...

  7. 如何在myEclipse中创建配置文件,比如:XXX.properties

    myEclipse是没有直接生成配置文件的方法,除非去配置某些插件. 目前通用的方法是:随便新建一个文件(比如:XXX.xml),然后对该文件重命名,改成XXX.properties即可. 很简单有没 ...

  8. HTML中table边框的显示总结

    一.1.显示表格的4个边框:<table border frame=box>2.只显示上边框: <table border frame=above>3.只显示下边框: < ...

  9. 如何用Qt写一个同一时间只能运行一个实例的应用程序

    http://blog.sina.com.cn/s/blog_6343941a0100nk2x.html 可以达到的目的: 1.应用只启动一个实例,依赖于QtNetwork模块 2.启动时向另一个实例 ...

  10. dataframe按值(非索引)查找多行

    很多情况下,我们会根据一个dataframe里面的值来查找而不是根据索引来查找. 首先我们创建一个dataframe: >>> col = ["id"," ...