Skip to content

Instantly share code, notes, and snippets.

@UnixSage
Last active March 3, 2021 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UnixSage/e108dd1889d6da0f835a1e357b1b2084 to your computer and use it in GitHub Desktop.
Save UnixSage/e108dd1889d6da0f835a1e357b1b2084 to your computer and use it in GitHub Desktop.
SysAdmin Password Tool
#!/usr/bin/env python3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from random import choice
import string
import getopt, sys
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "AaHhIc:l:PpSv9", ['help'])
except getopt.GetoptError:
usage()
sys.exit(2)
length = 8
count = 1
verbose = False
itu = False
addpunc = False
addspecial = False
chars = ''
phonics = {}
letters = (
'alfa', 'bravo', 'charlie', 'delta', 'echo', 'foxtrot', 'golf',
'hotel', 'india', 'juliett', 'kilo', 'lima', 'mike', 'november',
'oscar', 'papa', 'quebec', 'romeo', 'sierra', 'tango', 'uniform',
'victor', 'whiskey', 'x-ray', 'yankee', 'zulu'
)
numbers = (
'Zero', 'One', 'Two', 'Three', 'Four',
'Five', 'Six', 'Seven', 'Eight', 'Nine'
)
punctuation = {
'!': 'Exclamation', '#': 'Pound', '"': 'DoubleQuote', '%': 'Percent',
'$': 'Dollar', "'": 'SingleQuote', '&': 'Ampersand', ')': 'CloseParen',
'(': 'OpenParen', '+': 'Plus', '*': 'Asterisk', '-': 'Dash', ',': 'Comma',
'/': 'ForwardSlash', '.': 'Period', ';': 'SemiColon', ':': 'Colon',
'=': 'Equal', '<': 'Lessthan', '?': 'Question', '>': 'Greaterthan',
'@': 'At', '[': 'OpenBracket', ']': 'CloseBracket', '\\': 'Backslash',
'_': 'Underscore', '^': 'Carret', '`': 'Backtic', '{': 'OpenCurly',
'}': 'CloseCurly', '|': 'Bar', '~': 'Tilde'
}
for x in range(len(numbers)):
phonics[str(x)]=numbers[x]
for x in letters:
phonics[x[0]]=x
for x in letters:
phonics[x[0].upper()]=x.upper()
for x in punctuation:
phonics[x]=punctuation[x]
for o, a in opts:
if o == "-v":
verbose = True
if o == "--help":
usage()
sys.exit()
if o in ("-l"):
length = int(a)
if o in ("-c"):
count = int(a)
if o in ("-A"):
chars+=string.ascii_uppercase
if o in ("-a"):
chars+=string.ascii_lowercase
if o in ("-I"):
itu=True
if o in ("-p"):
chars+=string.punctuation
if o in ("-P"):
addpunc=True
if o in ("-S"):
addspecial=True
specialchars = "!@#$%^&*()_+-=[]{\\}|'"
if o in ("-9"):
chars+=string.digits
if o in ("-H"):
chars=string.digits + 'ABCDEF'
if o in ("-h"):
chars=string.digits + 'abcdef'
if len(chars) == 0:
if addpunc:
chars=string.ascii_letters+string.digits+string.punctuation
elif addspecial == True:
chars=string.ascii_letters+string.digits+specialchars
else:
chars=string.ascii_letters+string.digits
if verbose == True:
print("possible values per character", len(chars))
print("number of charactors", length)
print("total number of combinations", len(chars)**length)
for x in range(0,count):
passwd=GenPasswd(length,chars)
if itu:
print(passwd,'- (', end=' ')
for x in range(len(passwd)):
print(phonics[passwd[x]],end=' ')
print(')')
else:
print(passwd)
def usage():
print("""
GenPass 1.1 Copyright (C) 2019 John C. Place <http://www.unixsage.com>
This program comes with ABSOLUTELY NO WARRANTY!
This is free software, and you are welcome to redistribute it
under certain conditions; http://www.gnu.org/licenses/gpl.txt
Usage: genpass.py [OPTIONS]
-l length of password
-c number of passwords to generate
Character Sets
-h hex only (0-9,a-f)
-H HEX only (0-9,A-F)
-A Upper case Letters (A-Z)
-a Lower case Letters (a-z)
-9 Digits (0-9)
-p punction !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
-P Add Punction to default set
-S Add Special Characters - !@#$%^&*()_+-=[]{\\}|'
Display Options
-v Verbose
-I ITU Phonetics
Defaults to one 8 char password containing a-z,A-Z,0-9
""")
def GenPasswd(length, chars):
newpasswd=""
for i in range(length):
newpasswd = newpasswd + choice(chars)
return newpasswd
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment