-
Notifications
You must be signed in to change notification settings - Fork 0
/
givemepwd.pl
executable file
·26 lines (24 loc) · 996 Bytes
/
givemepwd.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl
=pod
A simple perl program that creates random password strings from alphanumeric characters (0-9, a-z, A-Z)
Usage: perl script.pl [password length]
If no length is provided, it defaults to 16 characters.
To see this help message, use the --help flag.
Written by Kobe Subramaniam (@kobebigs), [email protected]
=cut
use strict;
use warnings;
if (defined $ARGV[0] && ($ARGV[0] eq '--help' || $ARGV[0] eq '-h')) {
print "Generates a random password with the specified length.\n";
print "If no length is provided, it defaults to 16 characters.\n";
print "Usage: perl $0 [password length]\n";
print "Example: perl $0 36 - will generate a 36 characters password.\n";
exit;
}
my $pwdsize = defined $ARGV[0] ? int($ARGV[0]) : 16;
if ($pwdsize <= 0) {
die "Usage: perl $0 [password length eg: 8, 16, 32, 36...]\n";
}
my @ranstr = ('0'..'9', 'a'..'z', 'A'..'Z');
my $pwdstr = join '', map $ranstr[rand @ranstr], 0 .. ($pwdsize-1);
print "Here you go >> $pwdstr\n";