Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Python3 and masOS Monterey #13

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Binary file removed Password-Generator-2.1.3.alfredworkflow
Binary file not shown.
Binary file added Password-Generator-3.0.0-alpha-1.alfredworkflow
Binary file not shown.
16 changes: 7 additions & 9 deletions src/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@

"""

from __future__ import (
print_function,
unicode_literals,
absolute_import,
division
)


import abc
import logging
Expand Down Expand Up @@ -90,13 +85,13 @@ def password(self, strength=None, length=None):
length = int(math.ceil(strength / self.entropy))

chars = self.data
pw = [chars[ord(c) % len(chars)] for c in os.urandom(length)]
pw = [chars[c % len(chars)] for c in os.urandom(length)]
return ''.join(pw), self.entropy * length

@property
def entropy(self):
"""Entropy per element (character word) in bits."""
return math.log(len(self.data), 2)
return math.log(len(list(self.data)), 2)

@abc.abstractproperty
def id(self):
Expand Down Expand Up @@ -146,7 +141,6 @@ class WordGenBase(PassGenBase):

def _password_by_iterations(self, iterations):
"""Return password using ``iterations`` iterations."""
words = []
rand = random.SystemRandom()
words = [rand.choice(self.data) for i in range(iterations)]
return '-'.join(words), self.entropy * iterations
Expand Down Expand Up @@ -252,6 +246,10 @@ def get_generators():
if klass.__name__ == 'WordGenBase':
continue

# TODO: fix ignored generators
# if klass.__name__ in ['PronounceableGenerator']:
# continue

try:
inst = klass()
log.debug('Loaded generator : `%s`', inst.name)
Expand Down
4 changes: 2 additions & 2 deletions src/generators/gen_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

"""

from __future__ import print_function, unicode_literals, absolute_import


import string

from generators import PassGenBase, punctuation
from . import PassGenBase, punctuation


class AsciiGenerator(PassGenBase):
Expand Down
5 changes: 2 additions & 3 deletions src/generators/gen_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
A password generator based on the contents of ``/usr/share/dict/words``
"""

from __future__ import print_function, unicode_literals, absolute_import


from generators import WordGenBase
from . import WordGenBase


class WordlistGenerator(WordGenBase):
Expand All @@ -39,7 +38,7 @@ def __init__(self):
def data(self):
if not self._words:
words = set()
with open(self._filepath, 'rb') as fp:
with open(self._filepath, 'r') as fp:
for line in fp:
line = line.strip()
if not line or len(line) > self._maxlen:
Expand Down
3 changes: 1 addition & 2 deletions src/generators/gen_german.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

"""

from __future__ import print_function, unicode_literals, absolute_import


from .gen_basic import AsciiGenerator, AlphanumGenerator
from .gen_pronounceable_markov import PronounceableMarkovGenerator


# Umlauts, lovely umlauts
german_chars = 'ÄäÖöÜüß'

Expand Down
2 changes: 1 addition & 1 deletion src/generators/gen_hex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Created on 2016-02-24
#

from generators import PassGenBase
from . import PassGenBase


class HexGenerator(PassGenBase):
Expand Down
10 changes: 4 additions & 6 deletions src/generators/gen_pronounceable.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
http://stackoverflow.com/a/5502875/356942
"""

from __future__ import print_function, unicode_literals, absolute_import


import itertools
import string

from generators import WordGenBase
from . import WordGenBase


initial_consonants = (
Expand Down Expand Up @@ -64,10 +64,8 @@ def __init__(self):
def data(self):
if not self._syllables:
# each syllable is consonant-vowel-consonant "pronounceable"
self._syllables = map(''.join,
itertools.product(initial_consonants,
vowels,
final_consonants))
self._syllables = list(map(''.join, itertools.product(initial_consonants, vowels, final_consonants)))

return self._syllables

@property
Expand Down
9 changes: 2 additions & 7 deletions src/generators/gen_pronounceable_markov.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@

"""

from __future__ import (
print_function,
unicode_literals,
absolute_import,
division
)


from collections import defaultdict
import itertools
import os
import string
import random

from generators import WordGenBase
from . import WordGenBase


# Markov chain code from
Expand Down
Loading