There are plenty of ONLINE websites that claimed to be generating your password OFFLINE. This sounds quite absurd to me, as there are no way to tell if they are collecting your data or not, unless you look into their Javascript code or something. At the end of the day, generating one's password using someone else's website just doesn't make sense. Therefore, this code is meant to be run locally and is easy to understand, which is essential to provide confidence that it is safe.
python3 random_password_generator.py
Y?otqi3h8$DA9M-&=TWb
ixjF~_!$Vu*qE&49io#*
#B*dzjcDv$ezzD!mcR?U
bvV9NseA9naxA7YodQBF
kJDCoAU39Ueuebf5WMQw
xeWeq8o4sHd63qjTogx9
MIT License
Copyright (c) 2020 davidhcefx
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
from os import urandom
from random import shuffle
# Written by davidhcefx, 2020.3.16.
print('===============================================================================')
print('|| Offline Random Password Generator ||')
print('===============================================================================')
print('')
ln = input('> Password Length: (strong: >= 16) ').strip()
length = 16 if ln == '' else int(ln)
print('length = %d\n' % length)
print('Choose Character Set: [default = 12345]')
print('[1] Lowercase + Uppercase')
print('[2] Digits')
print('[3] Symbols')
print('[4] EXCLUDE Similar Characters: I l 1 O 0')
print('[5] EXCLUDE Ambiguous Characters: {}[]()<>/\\\'\"`;:,.')
choice = input('> ').strip()
if choice == '':
choice = '12345'
charset = []
exclude_alnum = ''
exclude_symbol = ''
# Exclude similar
if '4' in choice:
exclude_alnum = 'Il1O0'
# Exclude ambiguous
if '5' in choice:
exclude_symbol = '{}[]()<>/\\\'\"`;:,.'
# Lower + Upper
if '1' in choice:
alpha = [chr(i) for i in range(ord('a'), ord('z') + 1)] \
+ [chr(i) for i in range(ord('A'), ord('Z') + 1)]
for a in alpha:
if a not in exclude_alnum:
charset.append(a)
# Digits
if '2' in choice:
for i in range(ord('0'), ord('9') + 1):
if chr(i) not in exclude_alnum:
charset.append(chr(i))
# Symbols
if '3' in choice:
all_symbols = [chr(i) for i in range(0x21, 0x2f + 1)] \
+ [chr(i) for i in range(0x3a, 0x40 + 1)] \
+ [chr(i) for i in range(0x5b, 0x60 + 1)] \
+ [chr(i) for i in range(0x7b, 0x7e + 1)]
for s in all_symbols:
if s not in exclude_symbol:
charset.append(s)
print('charset:', ''.join(charset))
shuffle(charset) # mitigate the probability bias in [0,255] % len(charset)
passwd = []
for i in urandom(length):
passwd.append(charset[i % len(charset)])
print('\n> Here is your generated password: ', ''.join(passwd))