如何在bash中检查密码

时间:2012-04-02 10:55:41

标签: bash pam

是否可以在bash脚本中检查用户密码是否正确?如果是这样,请告诉我如何。谢谢

1 个答案:

答案 0 :(得分:2)

这对我有用:

#ensure sudo isn't saving a recent password
sudo -k

#prime it
echo $ROOTPASSWORD | sudo -S echo hello &> /dev/null

#test it
if ! [ "$(sudo -n echo hello 2>&1)" == "hello" ]; then
    echo "Incorrect password was entered"
fi