htpasswd生成的密码校验

用htpasswd生成密码

htpasswd -cb .htpasswddb username 123456

username:$apr1$nTkzCbrW$pt3i4h5WtWHJVlAfL.MFR1

The $apr1$ is the hashing method,nTkzCbrW is the salt, and the last string is the hashed password. You can validate it using openssl using
vim checkuserpasswd.sh
#! /bin/sh

username=$1
passwdfile=.htpasswddb
salt=$(cat $passwdfile | cut -d$ -f3)

password=$(openssl passwd -apr1 -salt $salt)

grep -q $username:$password $passwdfile
if [ $? -eq 0 ]
then
  echo "password is valid"
else
  echo "password is invalid"
fi

执行./checkuserpasswd.sh username
输入密码:123456
输出:password is valid

 
喜欢 0
分享