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码来验证
随机推荐
- ucsc genome brower的用法和说明(一)
官网说明书:http://genome.ucsc.edu/goldenpath/help/hgTracksHelp.html 1.genome brower的作用 a,展示任何尺度的基因组片段.比如, ...
- 自己的第一个MapReduce程序
数据源:来自互联网招聘hadoop岗位的薪资数据,其中几行示例数据如下: 美团 3-5年经验 15-30k 北京 [够牛就来]hadoop高级工程... 北信源 3-5年经验 15-20k 北京 Ja ...
- java异常和错误类总结(2016.5)
看到以前2016.5.写的一点笔记,拿过来放在一起. java异常和错误类总结 最近由于考试和以前的面试经常会遇到java当中异常类的继承层次的问题,弄得非常头大,因为java的异常实在是有点多,很难 ...
- 【arc101】比赛记录
这场还好切出了D,rt应该能涨,然而这场的题有点毒瘤,700分的D没多少人切,更别说EF了.(暴打出题人)既然这样,干脆就水一篇博客,做个简单的比赛记录. C - Candles 这题是一道一眼题,花 ...
- Spark常用算子-value数据类型的算子
package com.test; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; im ...
- How to use the ZooKeeper driver for ServiceGroup in OpenStack Nova
ServiceGroup APIs Nova会从ServiceGroup API 中查询节点的存活信息. ServiceGroup API 工作流程是: 当一个compute worker (runn ...
- 【转】移动oracle LOB索引到其他表空间
http://blog.chinaunix.net/uid-22948773-id-3451103.html
- iOS系统声音服务(System Sound Services)
系统声音服务(System Sound Services)提供了一个接口,用于播放不超过30秒的声音.它支持的文件格式有限,具体地说只有CAF.AIF和使用PCM或IMA/ADPCM数据的WAV文件. ...
- 快速的熟悉一个angular的项目从run看起
config之类的都会注入到controller或者run里边
- node.js 操作excel
首先安装依赖库node-xlsx npm install node-xlsx 在操作文件中直接引用 var xlsx = require("node-xlsx"); 读取excel ...