How to Generate Type-Friendly Password pt. 3

I do hope I wouldn’t need to come up with even more type-friendly password generators than this version. After making two, one for generic, one for copy-paste, versions of password generators, I am now hit with one of the weirdest policies I’ve encountered yet: there were different limits on how many digits and special characters a password can have. I don’t have a word to describe the misery I felt. At least the website in question supported up to 16 characters long password.

Instructions

Yet again, it’s in Python. The changes are only minor, so no doubt common Python environments can handle this without additional libraries.

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

special_character_permitted = ['!','@','#','$', '^', '&']
string_mix = [(string.ascii_lowercase, 6),
	(string.ascii_uppercase, 6),
	(string.digits, 2),
	(special_character_permitted, 2)
	]

pattern = []

for idx in range(len(string_mix)):
	rndset = secrets.choice(string_mix)
	for iidx in range(rndset[1]):
		pattern.append(secrets.choice(rndset[0]))
	string_mix.remove(rndset)

print(*pattern, sep='')

As always, the first variable you can change is the special characters permitted. What’s added this time is the next string_mix, where there are four tuples in form of (x, a). Looking at the default values, it will generate a password of 6 lowercases, 6 uppercases, 2 digits, and 2 special characters long password. You can change the length freely, and the location of each set is still randomized. And this would be the example password:

26#@YLQVJIoamrfu

Now, if a website or an app asks for a password with rather obscure (such as only up to 2 special characters) set of password, here is a simple copy-paste solution for it with the much needed customization tools.

Leave a comment