Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #13 from leonklingele/fix-password-generation
Browse files Browse the repository at this point in the history
Fix password generation
  • Loading branch information
bndw committed Dec 9, 2015
2 parents 1771460 + 23864ed commit a0094c1
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions pick
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,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.uppercase + string.lowercase + string.punctuation + string.letters
# 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))

Expand Down

0 comments on commit a0094c1

Please sign in to comment.