diff options
-rw-r--r-- | util.py | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -0,0 +1,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)]) + |