Apache Htpasswd生成和验证密码
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生成和验证密码的更多相关文章
- 使用apache htpasswd生成加密的password文件,并使用.htaccess控制文件夹訪问
htpasswd 是apache的小工具.在apache安装文件夹bin下可找到. Usage: htpasswd [-cmdpsD] passwordfile username htpasswd - ...
- apache htpasswd.exe创建密码
一.使用apache htpasswd.exe创建密码文件,命令请看PHP推荐教程:apache htpasswd命令用法详解 apache htpasswd命令用法实例 1.如何利用htpasswd ...
- wordpress密码生成与登录密码验证
一.研究wordpress时wordpess的密码密码生成与登录密码验证方式很重要 WordPress密码已成为整合的首要目标,如何征服整合,就得了解WordPress密码算法. WordPress系 ...
- 使用htpasswd实现Nginx验证访问
Nginx是一个高性能的WEB服务器,越来越多的用户使用,如果您的某个站点不希望对外公开(比如PHPMyAdmin),可以使用htpasswd实现Nginx验证访问. 安装htpasswd htpas ...
- (6) openssl passwd(生成加密的密码)
该伪命令用于生成加密的密码 [root@docker121 ssl]# man -f passwd passwd (1) - update user's authentication tokens p ...
- 《Apache服务用户身份验证管理》RHEL6.3
1.安装apache软件包 Yum install httpd 2.启动apache服务 /etc/init.d/httpd restart 3.创建一个目录,内编辑一个index.html文件 4. ...
- Java下使用Apache POI生成具有三级联动下拉列表的Excel文档
使用Apache POI生成具有三级联动下拉列表的Excel文档: 具体效果图与代码如下文. 先上效果图: 开始贴代码,代码中部分测试数据不影响功能. 第一部分(核心业务处理): 此部分包含几个方面: ...
- 使用truelicense实现用于JAVA工程license机制(包括license生成和验证)
开发的软件产品在交付使用的时候,往往会授权一段时间的试用期,这个时候license就派上用场了.不同于在代码中直接加上时间约束,需要重新授权的时候使用license可以避免修改源码,改动部署,授权方直 ...
- javascript中怎样验证密码是否含有特殊符号、数字、大小写字母,长度是否大于6小于12
今天在温习了一下以前学过的知识,一般常用验证密码是通过正则表达式或是通过ASCII 一.用AscII码来验证
随机推荐
- MongoDB命令语法小用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using MongoDB; ...
- samtools+bcftools 进行SNP calling
两个软件的作用:1.samtools mpileup 主要是用于收集BAM文件中的信息,这个位点上有多少条read匹配,匹配read的碱基是什么,并将这些信息存储在BCF文件中.2.bcftools ...
- RDLC 微软报表 自定义函数
报表的空白处点右键,报表属性,CODE,按下面的格式输入自定义函数: Shared Function ShowDate(value as DateTime) as string if value< ...
- juniper常用命令
Juniper防火墙基本命令 get interface ethernet0/0 查看 端口 常用查看命令 Get int 查看接口配置信息 Get int ethx/x 查看指定接口配置信息 G ...
- Centos6.5安装apache
1:下载 官网: http://www.apache.org/ 官网下载很慢,从别的地方下载 2:安装 tar -zxvf /usr/local/httpd-2.2.9.tar.gz cd /usr/ ...
- 如何开启和禁止Linux系统的ping功能
在日常的网络维护和使用过程中,ping命令是最为常用的一个检测命令,它所使用的是ICMP协议,但是为了保护主机,很多时候我们需要禁止ICMP协议,在这种情况下,终端再使用ping命令检测,服务器是不会 ...
- RealThinClient SDK 学习笔记(1)
从客户端调用远程函数的两种方法 1: RtcClientModule1.Prepare('select'); // call the "select" function on th ...
- ViewPagerAdapter
) { ; } } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == arg1; } ...
- HDU 3966 & POJ 3237 & HYSBZ 2243 & HRBUST 2064 树链剖分
树链剖分是一个很固定的套路 一般用来解决树上两点之间的路径更改与查询 思想是将一棵树分成不想交的几条链 并且由于dfs的顺序性 给每条链上的点或边标的号必定是连着的 那么每两个点之间的路径都可以拆成几 ...
- YII2笔记之三
activeform布局findAll等不能满足where, order by, limit,底层调用了findByConditioncol-md col-lg的使用 view的方法,前三个常用ren ...