From 13580ac7db850dc1f31f2e44dea93a44607c0808 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 28 Sep 2011 21:24:54 +0200 Subject: added function to generate password --- util.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 util.py diff --git a/util.py b/util.py new file mode 100644 index 0000000..7051134 --- /dev/null +++ b/util.py @@ -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)]) + -- cgit v1.2.3-1-g7c22