I created a script in bash that checking the strength of a password comibination I want to add an option that the user can input a password from a text file (The user types -f and then the file path and the he gets a password review ) or he types the password without any option before
What I want to ask what I need to do if I want to use an argument. Like if the user doesnt use a file in order to read the password from text file he just type the password by himself
#!/bin/bash
while getopts ":f:" option; do
case $option in
f) password=`cat $OPTARG` ;;
esac
done
#evaluating how much chars the password has
password_length=${#password}
#counter for checking in how much sections the password meets the rquirements
count=0
#Creating an array for stroing reasons why the password is incorrect
requirements=(foo bar)
#Checking if password includes minimum of 10 characters
if [ $password_length -ge 10 ];
then
requirements[0]="Correct"
else
requirements[0]="Incorrect password syntax. The password
length must includes minimum of 10 characters"
fi
#checkig if the password includes both alphabet and number
if [[ "$password" == *[a-zA-Z]* && "$password" == *[0-9]* ]]
then
requirements[1]="Correct"
else
requirements[1]="Incorrect password syntax. The password
must includes both alphabet and number"
fi
#checking if password includes both the small and capital case letters.
if [[ "$password" == *[A-Z]* && "$password" == *[a-z]* ]];
then
requirements[2]="Correct"
else
requirements[2]="Incorrect password syntax. The password
must includes both the small and capital case letters"
fi
#checking whether the password is according to the requirements or not
#if yes count will equal to 3 at the end
for i in "${requirements[@]}"
do
if [[ $i == "Correct" ]];
then
let count++
fi
done
#if the counter count is equal to 3 print the password in light green color and return exit 0
if [[ $count -eq 3 ]];
then
echo -e "\e[92m$password"
# sleep - user has the time to see that the password's syntax is correct
sleep 3
exit 0
#if the count is not equal to 3 print the password in reg color and return exit 1
else
echo -e "\e[91m$password"
for i in "${requirements[@]}"
do
if [[ $i != "Correct" ]];
then
echo $i
fi
done
# sleep - user has the time to see that the password's syntax is incorrect and the reasons for that
sleep 6
exit 1
fi
so what to write in the script for take an argument what the user will type if he doesnt uses an option