Shell Script Validate Password

Write a script to validate a password. The password should be least 8 characters long, should contain both alphabet and number, contain small cap and large cap letters. If any of these conditions are not met, the script should flag the password as "weak password".

Showing Answers 1 - 3 of 3 Answers

Veeresh N

  • Mar 20th, 2016
 

Code
  1. echo "enter the password"

  2. read password

  3. len="${#password}"

  4.  

  5. if test $len -ge 8 ; then

  6.  

  7.     echo "$password" | grep -q [0-9]

  8.      if test $? -eq 0 ; then

  9.            echo "$password" | grep -q [A-Z]

  10.                 if test $? -eq 0 ; then

  11.                     echo "$password" | grep -q [a-z]  

  12.                       if test $? -eq 0 ; then

  13.                        echo "Strong password"

  14.                    else

  15.                        echo "weak password include lower case char"

  16.                    fi

  17.             else

  18.                echo "weak password include capital char"

  19.             fi

  20.      else

  21.        echo "please include the numbers in password it is weak password"  

  22.      fi

  23. else

  24.     echo "password lenght should be greater than or equal 8 hence weak password"

  25. fi

  Was this answer useful?  Yes

shailesh chanderiya

  • Aug 26th, 2017
 

read -p "please enter password:" pass
count=`echo ${#pass}`
if [[ $count -ne 8 ]];then
echo "Password length should be 8 charactore"
exit 1;
fi
echo $count | grep "[A-Z]" | grep "[a-z]" | grep "[0-9]" | grep "[@#$%^&*]"

if [[ $? -ne 0 ]];then

echo "Password Must contain upparcase ,lowecase,number and special charactor"
exit 2;

fi

  Was this answer useful?  Yes

Aleem

  • Sep 18th, 2018
 

please change echo $count to echo $pass at line no 7

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions