Skip to content

Instantly share code, notes, and snippets.

@calroc
Created December 2, 2013 22:33
Show Gist options
  • Save calroc/7760312 to your computer and use it in GitHub Desktop.
Save calroc/7760312 to your computer and use it in GitHub Desktop.
A simple and straightforward password generator that produces alphanumeric random strings of length ten omitting those characters that are easily confused with each other in various fonts. Ensures at least one character will be a numeral.
#!/usr/bin/env python
from string import letters, digits
from random import choice
# Get a list of unambiguous ASCII characters. (It must be a list as
# sets don't work with random.choice().)
chars = list(set(letters + digits) - set('oO0I1lB8S5b6'))
def _pwgen(n=10):
return ''.join(choice(chars) for _ in range(n))
def pwgen(n=10):
pw = ''
while not any(ch in digits for ch in pw):
pw = _pwgen(n)
return pw
if __name__ == '__main__':
print pwgen()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment