forked from projectatomic/atomic-devmode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwmake_friendly
executable file
·49 lines (43 loc) · 1.37 KB
/
pwmake_friendly
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
#!/bin/bash
#
# Copyright (C) 2015-2016 Red Hat, Inc.
#
# This file is part of atomic-devmode.
#
# atomic-devmode is free software: you can redistribute it
# and/or modify it under the terms of the GNU Lesser General
# Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# atomic-devmode is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Lesser General Public License for
# more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with atomic-devmode. If not, see
# <http://www.gnu.org/licenses/>.
set -euo pipefail
# This is a thin wrapper around pwmake which ensures that the password generated
# only has friendly chars. We do this the "dumb" way: just keep re-running
# pwmake until every char in the pw is friendly.
# A nice set adapted from http://stackoverflow.com/questions/55556
FRIENDLY_CHARS="ABCDEFGHJKLMNPRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789@#\$%^&*()-_=+[]{}:;\"',<.>/?:\\"
main() {
pw=$(pwmake "$@")
until good_pw "$pw"; do
pw=$(pwmake "$@")
done
echo "$pw"
}
good_pw() {
pw="$1"
for (( i = 0; i < ${#pw}; i++ )); do
if [[ "$FRIENDLY_CHARS" != *"${pw:$i:1}"* ]]; then
return 1
fi
done
}
main "$@"