Skip to content

Commit

Permalink
Change id_ property to id
Browse files Browse the repository at this point in the history
Rebuild workflow
  • Loading branch information
deanishe committed Oct 1, 2015
1 parent e50b05e commit 179ea07
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 56 deletions.
Binary file not shown.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Passwords of the same length (or even the self-same password) generated using di

For example, the single-digit password `1` has an entropy of 3.32 bits when generated by the Numeric algorithm because it is one of only 10 possible one-digit passwords. The same password generated by the ASCII algorithm has an entropy of 5.95 bits because it is one of 62 possible one-character passwords.

Of course, that's just in theory. A password generated by the German generator is theoretically more secure than the same password generated by the ASCII-only one because the former has more possible passwords of any given length. That only holds in practice if an attacker is also guessing passwords based on the German alphabet. If they're guessing based on ASCII, and the password only contains ASCII characters, the password is naturally no more secure than if it had been generated by the ASCII generator.
Of course, that's just in theory. A password generated by the German generator is theoretically more secure than the same password generated by the ASCII-only one because the former has more possible passwords of any given length. That only holds in practice if an attacker is also guessing passwords based on the German alphabet. If they're guessing based on ASCII, and the password only contains ASCII characters, the password is naturally as easily guessed as if it had been generated by the ASCII generator.

See [Password strength on Wikipedia](https://en.wikipedia.org/wiki/Password_strength#Random_passwords) for more information.

Expand Down Expand Up @@ -210,7 +210,7 @@ Generates digit-only passwords.

#### Pronounceable Nonsense Generator ####

Generates pronounceable passwords based on nonsense words. Based on [this GitHub comment](http://stackoverflow.com/a/5502875).
Generates pronounceable passwords based on nonsense words. Based on [this Stack Overflow answer](http://stackoverflow.com/a/5502875).


#### Dictionary Generator ####
Expand Down Expand Up @@ -255,15 +255,16 @@ Modules containing your custom generators *must* be named `gen_XXX.py`.

Only files matching the pattern `gen_*.py` will be imported.

Your generator classes *must* subclass `generators.PassGenBase` (or `generators.WordGenBase`), an abstract base class, and *must* have `id_`, `name`, `description` and `data` properties. These have the following purposes:
Your generator classes *must* subclass `generators.PassGenBase` or `generators.WordGenBase`, which are [abstract base classes][abcs], and *must* have `id`, `name`, `description` and `data` properties. These have the following purposes:

| Property | Purpose |
|---------------|-------------------------------------------------------------------------------|
| `id_` | Short name for your generator, used internally. |
| `name` | The human-readable name, shown in the configuration. |
| `id` | Short name for your generator; used internally. |
| `name` | The human-readable name; shown in the configuration. |
| `description` | The longer description shown beneath the generator name in the configuration. |
| `data` | Return a sequence of the characters to generate passwords from. |


The `data` property is used by the `entropy` property and `password()` method on the `PassGenBase` base class.

`PassGenBase` is designed for character-based passwords, i.e. `data` returns a string or other sequence of single characters. `WordGenBase` is for word-based passwords, i.e. `data` returns a sequence of multi-character strings. The main difference is in the implementation of length-based passwords.
Expand All @@ -286,7 +287,7 @@ class GermanGenerator(PassGenBase):
"""Generate passwords containing umlauts."""

@property
def id_(self):
def id(self):
return 'deutsch'

@property
Expand All @@ -311,7 +312,7 @@ class BorkGenerator(WordGenBase):
"""Bork-bork-bork"""

@property
def id_(self):
def id(self):
return 'bork'

@property
Expand Down Expand Up @@ -370,3 +371,4 @@ Initial release
[markov]: https://github.com/SimonSapin/snippets/blob/master/markov_passwords.py
[gibberish]: http://stackoverflow.com/a/5502875/356942
[entropy]: https://en.wikipedia.org/wiki/Entropy_(computing)
[abcs]: https://docs.python.org/2.7/library/abc.html#module-abc
28 changes: 18 additions & 10 deletions src/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
The default generators are contained in (and loaded from) the
other modules in this package matching the pattern ``gen_*.py``.
All generators must subclass ``PassGenBase`` in order to
be recognised by the workflow.
All generators must subclass ``PassGenBase`` or ``WordGenBase``
in order to be recognised by the workflow.
"""

Expand All @@ -37,12 +37,13 @@
import sys

__all__ = [
'get_subclasses',
'ENTROPY_PER_LEVEL',
'get_generators',
'get_subclasses',
'import_generators',
'ENTROPY_PER_LEVEL',
'PassGenBase',
'punctuation',
'WordGenBase',
]

imported_dirs = set()
Expand All @@ -57,22 +58,24 @@


class PassGenBase(object):
"""Base class for generators
"""Base class for generators.
Generators *must* subclass this abstract base class.
Generators *must* subclass this abstract base class (or
``WordGenBase``, which is a subclass of this class).
If you just use ``PassGenBase.register()``, the workflow
will not find the generator.
Subclasses must override the ``id_``, ``name``, ``description``
Subclasses must override the ``id``, ``name``, ``description``
and ``data`` properties to be valid generators.
A very simple generator can just return an interable of
A very simple generator can just return a sequence of
characters from ``data``. The ``password`` method of this
base class will then generate a random password of the
required length/strength from the interable's contents.
"""

__metaclass__ = abc.ABCMeta

def password(self, strength=None, length=None):
Expand All @@ -96,7 +99,7 @@ def entropy(self):
return math.log(len(self.data), 2)

@abc.abstractproperty
def id_(self):
def id(self):
"""Short name of the generator.
Used in settings to identify the generator.
Expand Down Expand Up @@ -136,7 +139,12 @@ def _get_generator_modules(dirpath):


class WordGenBase(PassGenBase):
""""""
"""Base class for word-based generators.
Usage is the same as ``PassGenBase`` except ``data`` should
be a sequence of words, not characters.
"""

def _password_by_iterations(self, iterations):
"""Return password using ``iterations`` iterations."""
Expand Down
8 changes: 4 additions & 4 deletions src/generators/gen_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AsciiGenerator(PassGenBase):
"""Simple ASCII password generator."""

@property
def id_(self):
def id(self):
return 'ascii'

@property
Expand All @@ -48,7 +48,7 @@ class AlphanumGenerator(PassGenBase):
"""Simple alphanumeric password generator."""

@property
def id_(self):
def id(self):
return 'alphanumeric'

@property
Expand All @@ -68,7 +68,7 @@ class AlphanumClearGenerator(PassGenBase):
"""Simple alphanumeric password generator w/out confusable characters."""

@property
def id_(self):
def id(self):
return 'alphanumeric-clear'

@property
Expand All @@ -90,7 +90,7 @@ class NumericGenerator(PassGenBase):
"""Simple numeric password generator."""

@property
def id_(self):
def id(self):
return 'numeric'

@property
Expand Down
4 changes: 1 addition & 3 deletions src/generators/gen_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

from __future__ import print_function, unicode_literals, absolute_import

import math
import random

from generators import WordGenBase

Expand Down Expand Up @@ -53,7 +51,7 @@ def data(self):
return self._words

@property
def id_(self):
def id(self):
return 'dictionary'

@property
Expand Down
6 changes: 3 additions & 3 deletions src/generators/gen_german.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GermanGenerator(AsciiGenerator):
"""ASCII + German characters."""

@property
def id_(self):
def id(self):
return 'german'

@property
Expand All @@ -50,7 +50,7 @@ class GermanAlphanumericGenerator(AlphanumGenerator):
"""German alphabet and digits."""

@property
def id_(self):
def id(self):
return 'german-alphanumeric'

@property
Expand All @@ -72,7 +72,7 @@ class GermanPronounceableGenerator(PronounceableMarkovGenerator):
_sample_file = 'german.txt'

@property
def id_(self):
def id(self):
return 'pronounceable-german'

@property
Expand Down
2 changes: 1 addition & 1 deletion src/generators/gen_pronounceable.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def data(self):
return self._syllables

@property
def id_(self):
def id(self):
return 'pronounceable'

@property
Expand Down
2 changes: 1 addition & 1 deletion src/generators/gen_pronounceable_markov.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(self):
self._generator = None

@property
def id_(self):
def id(self):
return 'pronounceable-markov'

@property
Expand Down
Loading

0 comments on commit 179ea07

Please sign in to comment.