- or download this
Getopt::Long::Configure ("bundling");
- or download this
* No space between function name and its opening parenthesis.
- or download this
## PARSE AND SET COMMAND-LINE OPTIONS
## -----------------------------------------------------
- or download this
my %flags=('symbols', 0, 'numbers', 0, 'uppercase', 0, 'lowercase', 0,
+ 'confusable', 0, 'help', 0, 'qty', 1);
- or download this
my %flags=map {$_ => 0 }
qw/symbols numbers uppercase lowercase confusable help);
$flags{qty}=1;
- or download this
my $pwdchars = join( '', map {chr} ( 0x21 .. 0x7e ));
$pwdchars =~ s/\d+// if ( $flags{numbers} );
...
$pwdchars =~ s/[a-z]+// if ( $flags{lowercase} );
$pwdchars =~ s/[_\W]+//g if ( $flags{symbols} );
$pwdchars =~ tr/1Il0O//d if ( $flags{confusable} );
- or download this
my $pwdchars = join '', map chr, 0x21 .. 0x7e;
for ($pwdchars) {
...
s/[_\W]+//g if $flags{symbols};
tr/1Il0O//d if $flags{confusable};
}
- or download this
# If user triggered the --help option flag, display and exit
if ($flags{help}) {
&DisplayUsage();
exit();
}
- or download this
print(USAGE), exit if $flags{help};
- or download this
my $kill=0; # flag to stop the script if input is invalid (or -
+-help is used)
my @errmsg; # error message descriptions
- or download this
if ($flags{qty} == 0 || $flags{qty} < 0) {
$flags{qty}=1;
}
- or download this
$flags{qty}=1 if $flags{qty} <= 0;
- or download this
$flags{qty}=1 unless $flags{qty} > 0;
- or download this
$flags{qty}=1 unless $flags{qty} >= 1;
- or download this
if ( length($pwdchars) == 0) {
- or download this
if ($pwdchars) {
- or download this
# Check that user has passed only 1 argument (LENGTH) other than optio
+ns flags, warn user, kill script
if ($#ARGV > 0 || $#ARGV < 0) {
- or download this
unless (@ARGV==1) {
- or download this
# Check for only numeric input in LENGTH argument, warn user, kill scr
+ipt
if ($ARGV[0] !~ /^[0-9]+$/) {
- or download this
# If any of the above validation tests triggered the $kill flag...
if ($kill == 1) {
...
print "** --------------------------------------------------------
+---------------\n\n";
exit(); # exit script
}
- or download this
for ( 0..$pwdlen-1 ) {
$pwd .= substr( $pwdchars, rand( $limit ), 1 );
}
- or download this
#!/usr/bin/perl
...
}
__END__
- or download this
genpass -snul 10
genpass
...
genpass abc def
genpass -snul abc
genpass -snul abc def
- or download this
C:\temp>genpass -scq10 10
v36Bhe2mE4
...
2ZqYMq6NS4
jRUhKdfs46
mV2qZJVnWb