Skip to content

Commit

Permalink
Merge pull request #5 from mgrbyte/master
Browse files Browse the repository at this point in the history
Bcrypt password manager - checkpw
  • Loading branch information
tseaver committed Oct 3, 2016
2 parents 01237c7 + a4e5526 commit 5d9ce31
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*.dll
__pycache__
src/*.egg-info

.eggs
.installed.cfg
.tox
bin
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ python:
# pending 3.3-compatible release
install:
- pip install .
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then pip install bcrypt; fi
script:
- python setup.py test -q
notifications:
Expand Down
46 changes: 28 additions & 18 deletions docs/narrative.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Using :mod:`zope.password`
This package provides a password manager mechanism. Password manager
is an utility object that can encode and check encoded
passwords. Beyond the generic interface, this package also provides
seven implementations:
eight implementations:

:class:`zope.password.password.PlainTextPasswordManager`

Expand All @@ -31,9 +31,9 @@ seven implementations:

:class:`zope.password.password.SSHAPasswordManager`

the most secure password manager that is strong against dictionary
attacks. It's basically SHA1-encoding password manager which also
incorporates a salt into the password when encoding it.
A password manager that is strong against dictionary attacks. It's
basically SHA1-encoding password manager which also incorporates a
salt into the password when encoding it.

:class:`zope.password.password.CryptPasswordManager`

Expand All @@ -48,16 +48,22 @@ seven implementations:
PASSWORD function in MySQL versions before 4.1. Note that this method
results in a very weak 16-byte hash.

:class:`zope.password.password.BCRYPTPasswordManager`

A manager implementing the bcrypt hashing scheme. Only available if
the bcrypt_ module is installed. This manager is considered the
most secure.

The ``Crypt``, ``MD5``, ``SMD5``, ``SHA`` and ``SSHA`` password managers
are all compatible with RFC 2307 LDAP implementations of the same password
encoding schemes.

.. note::
It is strongly recommended to use SSHAPasswordManager, as it's the
.. note::
It is strongly recommended to use the BCRYPTPasswordManager, as it's the
most secure.

The package also provides a script, :command:`zpasswd`,to generate principal
entries in typical ``site.zcml`` files.
The package also provides a script, :command:`zpasswd`, to generate
principal entries in typical ``site.zcml`` files.

Password Manager Interfaces
---------------------------
Expand Down Expand Up @@ -138,7 +144,7 @@ A typical :command:`zpasswd` session might look like:

.. code-block:: sh
$ ./bin/zpasswd
$ ./bin/zpasswd
Please choose an id for the principal.
Expand All @@ -158,21 +164,23 @@ A typical :command:`zpasswd` session might look like:
1. Plain Text
2. MD5
3. SHA1
4. SSHA
3. SMD5
4. SHA1
5. SSHA
6. BCRYPT
Password Manager Number [4]:
SSHA password manager selected
Password Manager Number [6]:
BCRYPT password manager selected
Please provide a password for the principal.
Password:
Verify password:
Password:
Verify password:
Please provide an optional description for the principal.
Description: The main foo
Description: The main foo
============================================
Principal information for inclusion in ZCML:
Expand All @@ -181,7 +189,9 @@ A typical :command:`zpasswd` session might look like:
id="foo"
title="The Foo"
login="foo"
password="{SSHA}Zi_Lsz7Na3bS5rz4Aer-9TbqomXD2f3T"
password="{BCRYPT}$2b$12$ez4eHl6W1PfAWix5bPIbe.drdnyqjpuT1Cp0N.xcdxkAEbA7K6AHK"
description="The main foo"
password_manager="SSHA"
password_manager="BCRYPT"
/>
.. _bcrypt: https://pypi.python.org/pypi/bcrypt
19 changes: 10 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def alltests():
author_email='zope-dev@zope.org',
description='Password encoding and checking utilities',
long_description=(
read('README.rst')
+ '\n\n' +
read('CHANGES.rst')
),
read('README.rst')
+ '\n\n' +
read('CHANGES.rst')
),
url='http://pypi.python.org/pypi/zope.password',
license='ZPL 2.1',
classifiers = [
Expand All @@ -67,24 +67,25 @@ def alltests():
'Framework :: Zope3'],
keywords='zope authentication password zpasswd',
packages=find_packages('src'),
package_dir = {'': 'src'},
package_dir={'': 'src'},
extras_require=dict(vocabulary=['zope.schema'],
test=['zope.schema', 'zope.testing'],
bcrypt=['bcrypt'],
),
namespace_packages=['zope'],
install_requires=['setuptools',
'zope.component',
'zope.configuration',
'zope.interface',
],
tests_require = [
tests_require=[
'zope.schema',
'zope.testing',
'zope.testrunner',
],
test_suite = '__main__.alltests',
include_package_data = True,
zip_safe = False,
test_suite='__main__.alltests',
include_package_data=True,
zip_safe=False,
entry_points="""
[console_scripts]
zpasswd = zope.password.zpasswd:main
Expand Down
10 changes: 10 additions & 0 deletions src/zope/password/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sys

PY3 = sys.version_info[0] == 3

if PY3:
text_type = str
bytes_type = bytes
else:
text_type = unicode
bytes_type = str
32 changes: 23 additions & 9 deletions src/zope/password/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@
factory=".legacy.MySQLPasswordManager"
/>

<configure zcml:condition="installed bcrypt">
<utility
name="BCRYPT"
provides=".interfaces.IMatchingPasswordManager"
factory=".password.BCRYPTPasswordManager"
/>
</configure>

<configure zcml:condition="installed crypt">
<utility
name="Crypt"
provides=".interfaces.IMatchingPasswordManager"
factory=".legacy.CryptPasswordManager"
/>
<utility
name="Crypt"
provides=".interfaces.IMatchingPasswordManager"
factory=".legacy.CryptPasswordManager"
/>
</configure>

<utility
Expand All @@ -58,19 +66,19 @@
<class class=".password.PlainTextPasswordManager">
<allow interface=".interfaces.IMatchingPasswordManager" />
</class>

<class class=".password.MD5PasswordManager">
<allow interface=".interfaces.IMatchingPasswordManager" />
</class>

<class class=".password.SMD5PasswordManager">
<allow interface=".interfaces.IMatchingPasswordManager" />
</class>

<class class=".password.SHA1PasswordManager">
<allow interface=".interfaces.IMatchingPasswordManager" />
</class>

<class class=".password.SSHAPasswordManager">
<allow interface=".interfaces.IMatchingPasswordManager" />
</class>
Expand All @@ -79,6 +87,12 @@
<allow interface=".interfaces.IMatchingPasswordManager" />
</class>

<configure zcml:condition="installed bcrypt">
<class class=".password.BCRYPTPasswordManager">
<allow interface=".interfaces.IMatchingPasswordManager" />
</class>
</configure>

<configure zcml:condition="installed crypt">
<class class=".legacy.CryptPasswordManager">
<allow interface=".interfaces.IMatchingPasswordManager" />
Expand Down

0 comments on commit 5d9ce31

Please sign in to comment.