Created
October 9, 2013 18:50
-
-
Save sillygwailo/6906171 to your computer and use it in GitHub Desktop.
Duane Storey's iPhone-friendly random password generator in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Duane Storey wrote an iPhone-friendly random password in PHP. | |
# http://www.migratorynerd.com/tips/iphone-friendly-strong-password-generator/ | |
# "Basically the idea is to only use mostly keys that are accessible without | |
# having to hit shift or the keyboard button that switches to symbol mode." | |
# This is a port to Python if you wanted to wanted to generate it using something | |
# like Pythonista for iOS. http://omz-software.com/pythonista/ | |
import random | |
def generate_password(length = 10): | |
# Enforce a minimum length of 10 symbols | |
length = max(10, length) | |
password = '' | |
available_symbols = [] | |
# These only require one tap per symbol | |
available_symbols.append('qwertyuiopasdfghjklzxcvbnm') | |
# These require two taps per symbol | |
available_symbols.append('QWERTYUIPASDFGHJKLZXCVBNM1234567890!?') | |
# These require three taps per symbol | |
available_symbols.append('[]{}#%^*+=_/|~<>?!') | |
# Remove this next line if you only want mostly easy-to-type passwords | |
password += available_symbols[2][ random.randint(0, len(available_symbols[2]) - 1) ] | |
# These two require two keypresses each, but make the password much stronger | |
password += available_symbols[1][ random.randint(0, len(available_symbols[1]) - 1) ] | |
password += available_symbols[1][ random.randint(0, len(available_symbols[1]) - 1) ] | |
for i in range(0, length - len(password)): | |
password += available_symbols[0][ random.randint(0, len(available_symbols[0])) - 1 ] | |
# http://www.php2python.com/wiki/function.str-shuffle/ | |
characters = list(password) | |
random.shuffle(characters) | |
return ''.join(characters) | |
if __name__ == '__main__': | |
print generate_password() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment