Skip to content

Commit

Permalink
A more secure 'choice' for password generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
prabi committed May 9, 2019
1 parent aa74cec commit 4f694d1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pypass/passwordstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
import os
import subprocess
import string
import random
import re

from .entry_type import EntryType

# Secure source of randomness for password generation
try:
from secrets import choice
except ImportError:
import random
_system_random = random.SystemRandom()
choice = _system_random.choice

# Find the right gpg binary
if subprocess.call(
['which', 'gpg2'],
Expand Down Expand Up @@ -188,7 +195,7 @@ def generate_password(digits=True, symbols=True, length=15):
if digits:
chars += string.digits

password = ''.join(random.choice(chars) for i in range(length))
password = ''.join(choice(chars) for i in range(length))
return password

@staticmethod
Expand Down

0 comments on commit 4f694d1

Please sign in to comment.