I have been working on this function in shell scripting to take up a password from a user and check if it satisfies the criteria of being an effective password but it always says password not strong enough. The password I'm trying to use is LK@12abc.
Here is my code:
function paq()
{
read -p "PASSWORD :-" password
pasq="^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$"
if [[ $password =~ $pasq ]]; then
echo "Valid password"
echo "The password is:- $password" >> user1.txt
echo "$password" >>password.txt
else
echo "password not strong enough"
fi
}
paq
It appears your password has to have:
So, with bash glob patterns:
if [[ $password == *[a-z]*[a-z]*[a-z]* ]] &&
[[ $password == *[A-Z]*[A-Z]* ]] &&
[[ $password == *[0-9]*[0-9]* ]] &&
[[ $password == *[!@#$\&*]* ]] &&
(( ${#password} == 8 ))
then
echo password OK
else
echo password does not satisfy criteria
fi
I'm surprised that I need to escape the & in the 4th test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With