Reputation: 49
Is it possible to check that user password is correct in bash script? If so please show me how. Thank you
Upvotes: 2
Views: 2601
Reputation: 1411
This works for me:
#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
Upvotes: 2