Skip to content

Commit 889ea0a

Browse files
pbailiebmcutler
authored andcommitted
Update sample_bin/ugly_password.pl (#13)
Added more disqualifying chars: \ % = These can be misinterpreted in certain situations.
1 parent 2eb8b69 commit 889ea0a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sample_bin/ugly_password.pl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env perl
22

33
# File: ugly_password.pl
4-
# Date: August 7, 2018
4+
# Original Date: August 7, 2018
5+
# Updated: October 25, 2018
56
# Author: Peter Bailie
67
#
78
# This will output to STDOUT a randomly generated ugly password using the
@@ -18,16 +19,19 @@
1819
my $PW_LENGTH = 32; # length of the ugly password in characters.
1920
my ($fh, $byte, $val, $output);
2021

22+
# These chars not allowed to help prevent some edge cases for copy/pasting to
23+
# psql, cli, and PHP. Indexed by ASCII value.
24+
my %chars_not_allowed = (34, "\"", 37, "%", 39, "'", 61, "=", 92, "\\", 96, "`");
25+
2126
open $fh, '<:raw', '/dev/random';
2227
$output = ""; # password output
2328
while (length $output < $PW_LENGTH) {
2429
# Read a random byte and scale it to range 33 - 126.
2530
read $fh, $byte, 1;
2631
$val = (unpack 'C', $byte) % 94 + 33;
2732

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) {
33+
# Make sure random $val qualifies as a char (not in the "not allowed" hash)
34+
if (!exists $chars_not_allowed{$val}) {
3135
# Character qualifies, append it to password.
3236
$output .= chr $val;
3337
}

0 commit comments

Comments
 (0)