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 - 18 of 18 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

Sathish Krishnan Venkatachalam

  • Aug 7th, 2020
 

read -p "Please enter password: " PASS
COUNT=`echo ${#PASS}`
if [[ $COUNT -lt 8 ]]; then
echo "Password must be of atleast 8 characters!"
exit 1
fi
echo "$PASS"
echo $PASS | grep "[a-z]" | grep "[A-Z]" | grep "[0-9]" | grep "[@#$%^&*]"
if [[ $? -ne 0 ]]; then
echo "Password must contain atleast 1 uppercase, lowercase, digits and special characters"
exit 2
fi
echo "Strong Password"

  Was this answer useful?  Yes

Akshay Deshmukh

  • Sep 13th, 2020
 

read -p "please enter password:" password
count=`echo ${#password}`
if [[ $count -ne 8 ]];then
echo "Password length should be 8 charactore"
exit 1;
fi
echo $password | 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

Shwetha N A

  • Jun 24th, 2021
 

#!/bin/bash
echo "Enter the password"
read password
len=echo ${#password}
if test $len -gt 8
then
echo $password | grep [A-Za-z][0-9] | grep "[@#$%^&*]"
echo "strong password"
else
echo "weak password"
fi

  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