The types of characters included in the build password can be controlled by parameters
#!/usr/bin/perl use strict;
Use warnings;
Use GETOPT::STD;
Sub Show_help {print "useage:\n";
print "newp-aansl\n";
Print "-a\t\t The password contains lower case letters (A-Z) \ n";
Print "-a\t\t The password contains upper case letters (A-Z) \ n";
Print "-n\t\t The password contains numerical character (0-9) \ n";
Print "-s\t\t The password contains special symbols\n";
Print "-u\t\t The password contains only unique characters\n";
Print "-l length\t Set the password length (default:6) \ n";
Exit 0; Sub Show_version {print version:0.2.1 Changed the default option:-L 9-ana.
2016-4-15\n ";
Exit 0;
### Main program use VARs QW ($opt _a $opt _a $opt _h $opt _l $opt _n $opt _s $opt _u $opt _v);
Getopts (' AAHL:NSUV ');
&show_version if $opt _v;
&show_help if $opt _h; My $len = $opt _l | | 9;
# Default Length 9 my $opt _cnt = 0;
My @rand_str = ();
# Store All of the characters my @num = QW (0 1 2 3 4 5 6 7 8 9); My @ABC = QW (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
My @abc = QW (a b c d e F g h i j k l m n o p q R S t u v w x y z); # My @sym = QW (! "$% & ' * +-. / : ; < = >?
@ [ \ ] ^ _ ` { | } ~); My @sym = QW (! $% & * +-./:; < = > @ [] ^ _ ' {|} ~); # no ' ' \ unshift (@sym, ' (', ') ', ' # ', ', ');
# to prevent Perl ' s complains or warnings.
My @all_sym = (@num, @ABC, @abc, @sym);
My @ch_src = ();
if (! $opt _a) && (! $opt _a) && (! $opt _n) && (! $opt _s)) {$opt _a++;
$opt _a++;
$opt _n++;
} if ($opt _a) {$opt _cnt++;
My $i = Rand @abc;
Unshift @rand_str, $abc [$i];
if ($opt _u) {if ($i >=1) {$ABC [$i-1] = shift @abc;
else {shift @abc;
} unshift (@ch_src, @abc);
} if ($opt _a) {$opt _cnt++;
My $i = Rand @ABC;
Unshift @rand_str, $ABC [$i];
if ($opt _u) {if ($i >=1) {$ABC [$i-1] = shift @ABC;
else {shift @ABC;
} unshift (@ch_src, @ABC);
} if ($opt _n) {$opt _cnt++;
My $i = Rand @num; Unshift @rAnd_str, $num [$i];
if ($opt _u) {if ($i >=1) {$num [$i-1] = shift @num;
else {shift @num;
} unshift (@ch_src, @num);
} if ($opt _s) {$opt _cnt++;
My $i = Rand @sym;
Unshift @rand_str, $sym [$i];
if ($opt _u) {if ($i >=1) {$sym [$i-1] = shift @sym;
else {shift @sym;
} unshift (@ch_src, @sym);
} if ($len < $opt _cnt) {print "The Count of characters[$len] should not is smaller".
"than Count of character types[$opt _cnt].\n";
exit-1; } if ($opt _u && $len > (@ch_src + @rand_str)) {print "The total number of characters[". (
@ch_src + @rand_str).
"] which could be contained".
"In password is smaller than the length[$len] of it.\n";
exit-1;
foreach (1.. $len-$opt _cnt) {My $i = Rand @ch_src;
Unshift @rand_str, $ch _src[$i];
if ($opt _u) {if ($i >=1) {$ch _src[$i-1] = shift @ch_src;
else {shift @ch_src;
} foreach (1. $len) {My $i = Rand @rand_str;
Print $rand _str[$i];
if ($i >=1) {$rand _str[$i-1] = shift @rand_str;
else {shift @rand_str;
} print "\ n";
Exit 0;
That's all the code this article has to share, and hopefully it will help you learn about Perl