From e18d6224e76e75c11464f1cfa032e71551ba1279 Mon Sep 17 00:00:00 2001 From: Leon Klingele Date: Mon, 7 Dec 2015 00:10:20 +0100 Subject: [PATCH 1/2] Fix characters used in generated passwords. Old: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ New: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ This adds numbers (0-9) and removes duplicate chars (a-z, A-Z) --- pick | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pick b/pick index a7eb041..7a79f2f 100755 --- a/pick +++ b/pick @@ -154,7 +154,7 @@ class Util(): rand_max = 256 rand_excess = (rand_max + 1) % length rand_limit = rand_max - rand_excess - chars = string.uppercase + string.lowercase + string.punctuation + string.letters + chars = string.digits + string.letters + string.punctuation def next_index(): while True: From 23864edb2cf9cdf5c15ff688157eff6d80f3b325 Mon Sep 17 00:00:00 2001 From: Leon Klingele Date: Mon, 7 Dec 2015 00:14:24 +0100 Subject: [PATCH 2/2] Password generation can be done much easier.. --- pick | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pick b/pick index 7a79f2f..e12cd40 100755 --- a/pick +++ b/pick @@ -151,16 +151,12 @@ class Safe(): class Util(): def generate_password(self, length=50): ''' Generates a random password of length ''' - rand_max = 256 - rand_excess = (rand_max + 1) % length - rand_limit = rand_max - rand_excess - chars = string.digits + string.letters + string.punctuation + # Use no more than 256 chars in this string, rest will not be used + chars = string.digits + string.punctuation + string.letters + num_chars = len(chars) def next_index(): - while True: - x = ord(urandom(1)) - if x <= rand_limit: - return x % length + return ord(urandom(1)) % num_chars return ''.join(chars[next_index()] for _ in range(length))