sub DisplayUsage { print <<" USAGE"; Usage: genpass [-OPTIONS] LENGTH Generate secure passwords LENGTH characters long. -s, --symbols\t\tExclude symbol characters. -n, --numbers\t\tExclude number characters. -u, --uppercase\t\tExclude uppercase characters. -l, --lowercase\t\tExclude lowercase characters. -q(X)\t\t\tCreate X number of passwords. --help\t\t\tDisplay this usage screen. Report bugs, comments, and questions to jbrown_home\@yahoo.ca USAGE } #### sub GenPass { my ($pwdlen, %flags) = @_; my $password=""; my $num; while (length ($password) < $pwdlen) { $num = GetRandNum (); if (($num >= 33 && $num <= 47) || ($num >= 58 && $num <= 64) || ($num >= 91 && $num <= 95) || ($num >= 123 && $num <= 126) ) { next if $flags{symbols} eq '0'; } if (($num >= 48 && $num <= 57)) { next if $flags{numbers} eq '0'; } if (($num >= 65 && $num <= 90)) { next if $flags{uppercase} eq '0'; } if (($num >= 97 && $num <= 122)) { next if $flags{lowercase} eq '0'; } redo; # Invalid character, try again } continue { $password .= chr($num); } return "$password\n"; }