blob: 7051134aa014197cfcd3d3cfe91b2caf6fcb014a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# -*- coding: utf-8 -*-
from random import Random
rng = Random()
righthand = '23456qwertasdfgzxcvbQWERTASDFGZXCVB'
lefthand = '789yuiophjknmYUIPHJKLNM'
allchars = righthand + lefthand
def generate_char(i, alternate_hands):
if not alternate_hands:
return rng.choice(allchars)
else:
if i%2:
return rng.choice(lefthand)
else:
return rng.choice(righthand)
def generate_password(length = 8, alternate_hands = True):
return ''.join([generate_char(i, alternate_hands) for i in xrange(length)])
|