OPS435 Assignment 2 - Bash

From CDOT Wiki
Revision as of 12:32, 22 August 2017 by Andrew (talk | contribs) (Andrew moved page OPS435 Assignment 2 to OPS435 Assignment 2 - Bash)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Due: 8th of April

Late penalties: 10% per day

Submit: on Blackboard

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.
  • contain at least 1 digit (0-9).
  • contain at least 1 lowercase letter.
  • contain at least 1 uppercase letter.
  • 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.

Important notes:

  • Generated passwords should place characters in random positions. For example, the single special character (@ # $  % & * + - =) should not always appear in the same position.
  • Generated passwords should not be always the same length.
  • 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.

Here are several sample runs:

[azzad.kara@localhost ~]$ pw
Valid password is l9&aOq1Pi5

[azzad.kara@localhost ~]$ pw
Valid password is F4bXSL=Lre13Y

[azzad.kara@localhost ~]$ pw
Valid password is z=nOt8XtD

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

[azzad.kara@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

[azzad.kara@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

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

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

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

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

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

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

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

[azzad.kara@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 @ #  $  %  &  *  +  -  =   

[azzad.kara@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 @ #  $  %  &  *  +  -  =