the 9 would satisfy [0-9]
the ! would satisfy the *
the a would satisfy the [a-z]
Also
9A
would be flagged as a bad password because Capital 'A' doesn't match [a-z].
typically I use egrep
a=`echo $VAR | egrep "[^0-9A-Za-z]"`
if [ "$a" eq $var ]; then
echo "password can only contain letters and numbers"
else
# we know it now contains letters or digits
b=`echo $VAR | egrep "[0-9]"`
c=`echo $VAR | egrep "[A-Za-z]"`
if [ "$b" eq "$c"] ; then
echo "password is valid"
else
echo "Password must contain both letters and digits"
fi
fi
I am not well verses in SH so if the eq isn't right please use the correct thing. ( maybe == ??)
The egrep is looking for all characters other than digits and letters and if it finds one it will return the string else it will return nothing and nothing means it only contains letters and numbers.
then you need the second set of egreps to make sure it contains both letters and digits. if the user only specifies letters "aaa" or digits "111" one of the greps will return nothing and the 2 strings will not compare.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.