In: Computer Science
UNIX/LINUX SCRIPT:
Create a named directory and verify that the directory is there by listing all its contents.
Write a shell script to validate password strength. Here are a few assumptions for the password string.
Length – a minimum of 8 characters.
• Contain alphabets , numbers , and @ # $ % & * symbols.
• Include both the small and capital case letters.
give a prompt of Y or N to try another password and displays an error if anything other than an N or Y is entered.
-If the password doesn’t comply to any of the above conditions, then the script should report it as a “Weak Password” otherwise display a “Strong Password”
If the password is Strong then the strong password will be added to a separate file named password.txt
and lastly display their contents of the password file, then delete the file and the directory and verify both are deleted.
The Shell Script is used in linux OS.
#!/bin/bash
echo "enter the password" //asking users to enter the
password
read password //reads the password.
len="${#password}" //initialising the strength
if test $len -ge 8 ; then //applying the password validation in if else loop.
echo "$password" | grep -q [0-9] //grep command is used to search for all the possibility and we are telling users to including the numerical values and the A-Z alphabets
if test $? -eq 0 ; then
echo "$password" | grep -q [A-Z]
if test $? -eq 0 ; then
echo "$password" | grep -q [a-z]
if test $? -eq 0 ; then
echo "$password" | grep -q [$,@,#,%]
if test $? -eq 0 ; then
echo "Strong password"
else
echo "weak password include special characters"
fi
else
echo "weak password include lower case character"
fi
else
echo "weak password include capital character"
fi
else
echo "please include the numbers in password it is weak password"
fi
else
echo "password length should be greater than or equal 8 hence weak password"
fi
#!/bin/bash
while true; do
echo "Enter password:"
read pwd
length="${#pwd}"
if test $length -ge 8; then
echo "$pwd" | grep -q [a-zA-Z0-9]
if test $? -eq 0; then
echo "$pwd" | grep -q ["@$#%&*"]
if test $? -eq 0; then
echo "Strong Password"
echo "$pwd" >> Passwords/password.txt
else
echo "Weak Password"
fi
else
echo "Weak Password"
fi
else
echo "Weak Password"
fi
read -p "Try another password(Y or N):" option
case "$option" in
N ) break;;
Y ) ;;
* ) echo "enter valid option";;
esac
done
Output