How to Generate Type-Friendly Password pt. 2

As I have written in the past on generating a type-friendly password with Python, it hit me like a freight truck today. One of the Korean apps have “upped” their security policy demanding now I type the password which is likely 20 or more characters, completely random, on a virtual keyboard. If you have never used one of those, it’s like a touchscreen keyboard, except all the locations are scrambled. Typing 20+ characters on those keyboard is an arduous task.

Instructions

As before, the code is in Python. You can use your Python environment of choice.

# !/usr/bin/env python3
	
import secrets
import string

set_length = 4
special_character_permitted = ['!','@','#','$', '^', '&']

string_mix = [string.ascii_lowercase, 
	string.ascii_uppercase, 
	string.digits,
	special_character_permitted
	]
pattern = []

for idx in range(len(string_mix)):
	rndset = secrets.choice(string_mix)
	for iidx in range(set_length):
		pattern.append(secrets.choice(rndset))
	string_mix.remove(rndset)

print(*pattern, sep='')

There are two variables you can change. One is the length of each set (and the total length will always be the four times the length value), and the other is the special characters that are permitted. Python does far more options for special characters, but the security policies don’t support all of them. So I chose the most common ones for this example. With the defaults, this is the example password:

JRKF^&!@pivh0262

The location of each set is also randomized. So in next iteration, it might be lowercase-digits … and so on. The key of the code is that it generates a string that is easier to type, (no need to shift the virtual keyboards per character) and also easier to copy to the password manager. I do hope password managers offer a regex-like tool that allows users to come up with their desired recipes.

Leave a comment