-
Notifications
You must be signed in to change notification settings - Fork 0
/
plpwgen
executable file
·112 lines (99 loc) · 3.49 KB
/
plpwgen
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/perl -w
# --------------------------------
# Sal's Random Password Generator
# --------------------------------
# It does what it says.
# --------------------------------
# Copyright (c) 2015, Salvatore LaMendola <salvatore@lamendola.me>
# All rights reserved.
use warnings;
use strict;
# Default length/number of passwords to generate
my $len = 19;
my $num = 1;
# Pull in args and list usage
my $numargs = scalar @ARGV;
if ($numargs == 0 || $ARGV[0] eq "-h") {
print "Sal's Random Password Generator\n";
print "-------------------------------\n";
print "Usage: plpwgen <OPTIONS> [length] [number] (length and number optional)\n\n";
print "OPTIONS (MUST SPECIFY ONE!):\n";
print "-s Add symbols to output (NOT FOR MYSQL!)\n";
print "-a Alphanumeric only\n";
print "-p Generate phpMyAdmin Blowfish secret (for cookie auth)\n";
print "-w Generate Wordpress encryption keys (wp-config.php)\n";
print "-h Display this usage information\n\n";
print "If no length or number are defined, a default length of $len and number of $num will be used.\n";
exit(0);
}
# Check for the password/secret type
my $pwtype = $ARGV[0];
# If a length was supplied, override the default
if (defined $ARGV[1] && $ARGV[1] =~ /^\d+$/) {
$len = $ARGV[1];
}
# If a number was supplied, override the default
if (defined $ARGV[2] && $ARGV[2] =~ /^\d+$/) {
$num = $ARGV[2];
}
sub pwgen{
# Custom definition for 'safe' symbols + alphanumeric
my @symbols = ('-', '_', '!', '@', '#', '$', '%', '^', '&',
'*', '/', '\\', '(', ')', '_', '+', '{', '}', '|', ':',
'<', '>', '?', '=', 'A'..'Z', 'a'..'z', '0'..'9');
# Alphanumeric-only option
my @alphanumeric = ('A'..'Z', 'a'..'z', '0'..'9');
# Time to do the actual generation
my $pass;
$pass = "";
if ($_[1] eq "symbols") {
$pass .= @symbols[rand @symbols] for 1..$_[0];
} elsif ($_[1] eq "alphanumeric") {
$pass .= @alphanumeric[rand @alphanumeric] for 1..$_[0];
} else {
exit(1);
}
return $pass;
}
# Generate random password(s) with symbols + alpha
if ($pwtype eq "-s") {
my $count = 0;
while ($count < $num) {
my $pass = pwgen($len, "symbols");
print "$pass\n";
$count++;
}
}
# Generate random password(s) with alphanumeric only
if ($pwtype eq "-a") {
my $count = 0;
while ($count < $num) {
my $pass = pwgen($len, "alphanumeric");
print "$pass\n";
$count++;
}
}
# Generate random phpMyAdmin Blowfish secret string
if ($pwtype eq "-p") {
my $pass = pwgen("64", "symbols");
print "$pass\n";
}
# Generate random encryption secrets for WordPress
if ($pwtype eq "-w") {
my $pass1 = pwgen("64", "symbols");
print "define('AUTH_KEY',\t\t'$pass1');\n";
my $pass2 = pwgen("64", "symbols");
print "define('SECURE_AUTH_KEY',\t'$pass2');\n";
my $pass3 = pwgen("64", "symbols");
print "define('LOGGED_IN_KEY',\t\t'$pass3');\n";
my $pass4 = pwgen("64", "symbols");
print "define('NONCE_KEY',\t\t'$pass4');\n";
my $pass5 = pwgen("64", "symbols");
print "define('AUTH_SALT',\t\t'$pass5');\n";
my $pass6 = pwgen("64", "symbols");
print "define('SECURE_AUTH_SALT',\t'$pass6');\n";
my $pass7 = pwgen("64", "symbols");
print "define('LOGGED_IN_SALT',\t'$pass7');\n";
my $pass8 = pwgen("64", "symbols");
print "define('NONCE_SALT',\t\t'$pass8');\n";
}