Jump to content

I have no idea where to start and im new to linux scripting.

 

 

Write a BASH shell script (program) named "pw" which validates or generates passwords. 

If "pw" is run without a parameter it will generate a random password based on these rules:

  • The password
    • must be at least 8 characters long but not longer than 16 characters.
    • must contain at least 1 digit (0-9).
    • must contain at least 1 lowercase letter.
    • must contain at least 1 uppercase letter.
    • must contain exactly one and only one of @ #  $  %  &  *  +  -  =

If "pw" is run without a parameter but with a "-h" option it will generate a "Usage/Help" synopsis of the command.

If "pw" is run with one parameter (a suggested password) it will be verified against the rules listed above.

Here are several examples:

[localhost ~]$ pw
Valid password is l9&aOq1Pi5

[localhost ~]$ pw
Valid password is F4bXSL=Lre13Y

[localhost ~]$ pw
Valid password is z=nOt8XtD

[localhost ~]$ pw
Valid password is ZpkMOpM9PGk@u

[localhost ~]$ pw abc
Error - Invalid Length - abc
Error - Does not contain Digit - abc
Error - Does not contain Uppercase Letter - abc
Error - Does not contain One Special Character - abc
abc is not a valid password

[localhost ~]$ pw abc1
Error - Invalid Length - abc1
Error - Does not contain Uppercase Letter - abc1
Error - Does not contain One Special Character - abc1
abc1 is not a valid password

[localhost ~]$ pw abc1Z
Error - Invalid Length - abc1Z
Error - Does not contain One Special Character - abc1Z
abc1Z is not a valid password

[localhost ~]$ pw abc1Z@
Error - Invalid Length - abc1Z@
abc1Z@ is not a valid password

[localhost ~]$ pw abc1Z@xxx
abc1Z@xxx is a valid password

[localhost ~]$ pw abc1Z@xx$
Error - Contains More than One Special Character - abc1Z@xx$
abc1Z@xx$ is not a valid password

[localhost ~]$ pw abc1Z@xxmamamama
abc1Z@xxmamamama is a valid password

[localhost ~]$ pw Amaiawabc1Z@xx
Amaiawabc1Z@xx is a valid password

[localhost ~]$ pw Amaiawabc1Z@xx123
Error - Invalid Length - Amaiawabc1Z@xx123
Amaiawabc1Z@xx123 is not a valid password

[localhost ~]$ pw -h
Usage: pw | pw -h | pw password
Note:    Valid passwords must be at least 8 characters long,
contain at least 1 digit,
contain at least 1 lowercase letter
contain at least 1 uppercase letter
contain one of @ #  $  %  &  *  +  -  =    

[localhost ~]$ pw abc xyz
Usage: pw | pw -h | pw password
Note:    Valid passwords must be at least 8 characters long,
contain at least 1 digit,
contain at least 1 lowercase letter
contain at least 1 uppercase letter
contain one of @ #  $  %  &  *  +  -  =    

[localhost ~]$ 
   

Notes:

  • Generated passwords should place characters in random positions. For example, the single special character (@ #  $  %  &  *  +  -  =) should not always appear in the same position. 
  • Your script will NOT use the "clear" command.
  • Your script will NOT prompt the user to enter any data if an error was discovered. It will just exit with an error code.
  • If the password is valid the exit code will be zero otherwise it will be one.
  • Your script will be properly documented and formatted.
  • Your script name will be "pw" without the quotes.

 

 

Link to comment
https://linustechtips.com/topic/322426-linux-bash-scripting-help/
Share on other sites

Link to post
Share on other sites

Uh...this looks like a literally copy-pasted homework assignment? Where's your code that you need help troubleshooting? Where are your actual questions?

 

That's what I was thinking... OP, are you trying to get someone to do your CompSci/CST homework for you?

#!/bin/bash          echo Do your own homework OP
Link to post
Share on other sites

having trouble doing this part. 

  • The password
    • must be at least 8 characters long but not longer than 16 characters.
    • must contain at least 1 digit (0-9).
    • must contain at least 1 lowercase letter.
    • must contain at least 1 uppercase letter.
    • must contain exactly one and only one of @ #  $  %  &  *  +  -  =

      Should I use grep???
Link to post
Share on other sites

having trouble doing this part.

  • The password
    • must be at least 8 characters long but not longer than 16 characters.
    • must contain at least 1 digit (0-9).
    • must contain at least 1 lowercase letter.
    • must contain at least 1 uppercase letter.
    • must contain exactly one and only one of @ #  $  %  &  *  +  -  =

      Should I use grep???

I would recommend regex.
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×