Skip to content

Commit c1b4e4d

Browse files
pbailiebmcutler
authored andcommitted
Ugly Password Script (#4)
* Ugly Password Script Generates a randomly generated long ugly password. Uses /dev/random to ensure reliable entropy. Could be used to password protect Submitty system accounts. * Fix Comment /sample_bin/ugly_password.pl Fix comment style line 23 * Ugly Password Fix sample_bin/ugly_password.pl Bugfix/refactor to disqualify certain printable chars that could confuse psql or possibly cli. * Ugly Password Comment Update sample_bin/ugly_password.pl Some comments didn't make it to last commit. * Ugly Password Script Changes to be committed: modified: sample_bin/ugly_password.pl
1 parent 54a8592 commit c1b4e4d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

sample_bin/ugly_password.pl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env perl
2+
3+
# File: ugly_password.pl
4+
# Date: August 7, 2018
5+
# Author: Peter Bailie
6+
#
7+
# This will output to STDOUT a randomly generated ugly password using the
8+
# printable ASCII character range of 33 - 126. Passwords are based on
9+
# /dev/random to ensure reliable pseudo-random entropy.
10+
#
11+
# /dev/random is blocking, so there may be a (possibly lengthy) delay in
12+
# output when the seed pool needs to be refreshed.
13+
14+
use strict;
15+
use warnings;
16+
use autodie;
17+
18+
my $PW_LENGTH = 32; # length of the ugly password in characters.
19+
my ($fh, $byte, $val, $output);
20+
21+
open $fh, '<:raw', '/dev/random';
22+
$output = ""; # password output
23+
while (length $output < $PW_LENGTH) {
24+
# Read a random byte and scale it to range 33 - 126.
25+
read $fh, $byte, 1;
26+
$val = (unpack 'C', $byte) % 94 + 33;
27+
28+
# Single quote, double quote, and backtick chars are disqualified.
29+
# Prevents some edge cases for copy/pasting ugly passwords to psql or cli.
30+
if ($val != 34 && $val != 39 && $val != 96) {
31+
# Character qualifies, append it to password.
32+
$output .= chr $val;
33+
}
34+
}
35+
close $fh;
36+
print STDOUT $output . "\n";

0 commit comments

Comments
 (0)