Welcome, guest | Sign In | My Account | Store | Cart

Generate passwords that can easily be typed with only the left hand, very simple script

Python, 32 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
import argparse
import random

parser = argparse.ArgumentParser(description='Generate a left-handed random password.')

parser.add_argument('-n', action='store', dest='passNum', default=8, type=int, help='Number of passwords to generate.')
parser.add_argument('-l', action='store', dest='passLen', default=8, type=int, help='Length of password')
parser.add_argument('-s', action='store', dest='passStrength', default=4, type=int, help='Strength of password (1-4)')

lowerChars = "qwertasdfgzxcvb"
upperChars = "QWERTASDFGZXCVB"
lowerNum = "123456"*3 # repeated digits for 'weight'
upperNum = '!"$%^'*3

results=parser.parse_args()

#Generate character to select from according to passStrength (-s)
if results.passStrength == 1:
	leftHand = lowerChars
elif results.passStrength == 2:
	leftHand = lowerChars+upperChars
elif results.passStrength == 3:
	leftHand = lowerChars+upperChars+lowerNum
elif results.passStrength == 4:
	leftHand = lowerChars+upperChars+lowerNum+upperNum

for i in range(results.passNum):
	leftPass = ''
	for j in range(results.passLen):
		leftPass = leftPass + leftHand[random.randint(0,len(leftHand)-1)]
	print leftPass

5 comments

obernard78+activestate 12 years, 6 months ago  # | flag

Pretty funny. I really like the intent of this recipe.

Have you considered using other functions of random module, such as choice or sample?

''.join(random.choice(leftHand) for j in range(results.passLen))
''.join(random.sample(leftHand * passLen, passLen))
Alex (author) 12 years, 6 months ago  # | flag

Thanks obernard :) Haha, the intention of this script was entirely innocent since I am left-handed, however my friend soon pointed out how it would be useful to the right-handed population and hence how it ended up here ;D

Alexander Thomas Cruz 12 years, 6 months ago  # | flag

I like it it is very cool.

Steven D'Aprano 12 years, 6 months ago  # | flag

I have a friend who lost his left hand in an industrial accident. Can he use his right hand to type the left-handed password?

<tongue firmly in cheek>

Stephen Kiel 12 years, 3 months ago  # | flag

Great example code.