1 edit |
Junior3
Member
2007-Oct-23 11:33 pm
How to make this script? 1. Write a portable bash shell script called change_password.bash that will prompt the user for a password. Use a series of if statements to test if:
1.
The password is NOT 6 or more characters 2.
The password does not contain at least 3 consecutive letters (could be either uppercase or lowercase) 3.
The password does NOT contain any number 4.
The password does NOT contain a non-alphanumeric character (eg. Something not a letter or number. I can take care of option 1 but have trouble making option 3,2 and 4.
#!/bin/bash read password echo $password | wc -m >number number=`cat number` if [ $number -gt 5 ] then echo Password cannot contain more then 5 numbers fi rm number |
|
Junior3 |
Junior3
Member
2007-Oct-23 11:39 pm
for 3 i can only think of this but it wont work for somereason
echo $password | grep [a-zA-z]* >part3 part3=`cat part3` if [ $part3 != $password ] then echo error password cannot contain numbers or special characters fi |
|
PetePumaHow many lumps do you want MVM join:2002-06-13 Arlington, VA |
to Junior3
Sounds like homework. Good luck. |
|
|
Junior3
Member
2007-Oct-24 10:08 am
any help |
|
|
There's sort of an unwritten rule here about doing someone else's homework for them.
If you ask a specific question about how a function works - why adding a backtick returns a different result - you may get some replies. |
|
|
Junior3
Member
2007-Oct-24 10:34 am
echo $password | grep [a-zA-z]* >part3 part3=`cat part3` if [ $part3 != $password ] then echo error password cannot contain numbers or special characters fi
why doesnt this script work with the above script?
also how do I search for consecutive letters |
|
|
|
to Junior3
Here is little script. sh code: #!/bin/bash
read -p "Enter password:" password echo $password
# 1 if [ ${#password} -gt 5 ]; then echo "Password more than 5 charater" fi
# 2 if ` echo "$password" | egrep -q '[a-zA-Z]{3,}' ` ; then echo "contain 3 consective letters" fi
# 3 if ` echo "$password" | egrep -vq '[0-9]' ` ; then echo "does not contain any number" fi
# 4 nonalp=` echo "$password" | sed 's/[a-zA-Z0-9]//g' ` if [ ${#nonalp} -le 0 ] ; then echo "No alphanumeric character"
fi
Here is bash script string manipulation » tldp.org/LDP/abs/html/st ··· ion.htmlAlso read man page of egrep. Hope this helps |
|
e9th join:2003-07-12 Miami, FL |
e9th
Member
2007-Oct-25 9:43 pm
I'm not sure you're really into the spirit of the exercise here, which seems to be about bash and portability.
1. It ain't bash! It's just a generic script that uses grep & sed to do the heavy lifting, and
2. It's not portable. Constructs like [A-Z] are locale dependant.
Everything can be done entirely by bash:
[[ ${#password} -ge 6 ]] || echo NOT 6 or more chars
[[ ${password} =~ [[:alpha:]]{3,} ]] || echo NOT 3 consecutive letters
[[ ${password} =~ [[:digit:]] ]] || echo Does NOT contain number
[[ ${password} =~ [^[:alnum:]] ]] || echo Does NOT contain non-alphanumeric
I figure it's safe to reply now since Junior's assignment has probably already been turned in. |
|
|
to Junior3
said by Junior3: 1. Write a portable bash shell script called change_password.bash that will prompt the user for a password. Use a series of if statements to test if: 1. The password is NOT 6 or more characters 2. The password does not contain at least 3 consecutive letters (could be either uppercase or lowercase) 3. The password does NOT contain any number 4. The password does NOT contain a non-alphanumeric character (eg. Something not a letter or number. I can take care of option 1 but have trouble making option 3,2 and 4. #!/bin/bash read password echo $password | wc -m >number number=`cat number` if [ $number -gt 5 ] then echo Password cannot contain more then 5 numbers fi rm number BCIT student? |
|
|
#!/bin/bash echo enter newpassword read password echo $password | wc -m >num echo $password | grep "[a-z]*[A-Z]*" | wc -m >num1 one=`cat num` two=`cat num1` echo $two if [ $one -gt 5 ] then echo password is more then five characters fi if [ $two = 0 ] then echo password cannot contain numbers or non-alphanumerica caracters only letters fi rm num num1
this is what i came up with and this is for school but its just a partice lab just want to know how do I search for alpha is there a way thorught grep |
|