My code fails to validate some of the logical criteria giving in the if statement. I'm new to bash so any help would be great. My code runs, but fail in my logic. Also, I would like to learn more advance ways to write bash script. Any suggestions would be greatly appreciated.
function validatePassword ()
{
local stat=1 #assigns 1 to (stat)
local pass=$1
LEN=${#pass} #counts each character in the password length
echo $LEN #Prints string length
#checks for nums chesks for lowercase checks for uppercase checks if pass is greater than 8
if [[ $pass =~ [0-9] ]] && [[ $pass =~ [a-z] ]] && [[ $pass =~ [A-Z] ]] && [[ "$LEN" -ge 8 ]]; then
stat=$? #return 1 for false
fi
return $stat
}
function encryptPassword ()
{
dual=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
phrase=$encryptedPassword
rotat=13
newphrase=$(echo $phrase | tr "${dual:0:26}" "${dual:${rotat}:26}")
echo "Your encrypted password is ${newphrase}"
}
#Promts the user for input storing into variable PASSWORD
read -p "Enter your password:" -e PASSWORD
passwordToCheck=$PASSWORD
encryptedPassword=$PASSWORD
validatePassword $passwordToCheck #Calls function passsing value of (PASSWORD)
encryptPassword $encryptedPassword #Calls function passing value of (PASSWORD)
if [[ $? -ne 0 ]]; then #(-ne) not equal command
echo "Invalid password"
else
echo "Password is valid"
fi
#! /bin/bash
read -p "Enter a numbers:" -e input #Prompt & read string. echo "Your input is $input" echo # passwd >= 8 #check uppder #check lower #check for num if echo "$input" | egrep "^.{8,255}" | egrep "[A-Z]"| egrep "[a-z]" | egrep "[0-9]"; then echo "Password is valid" else echo "Password is invalid" fi
echo "$input" | tr 'A-Za-z0-5' 'N-ZA-Mn-za-m6-9-5'
exit 0
validatePasswordandencryptPassword)?