Commits

Steve Losh  committed 968905b

Initial commit.

  • Participants
  • Tags v0.9.0

Comments (0)

Files changed (6)

+syntax: glob
+
+*.pyc
+.DS_Store
+.project
+.pydevproject
+*.swp
+*.un~
+
+syntax: regexp
+^build$
+^dist$
+^django_bcrypt.egg-info$

File LICENSE.markdown

+Copyright (c) 2010 Dumbwaiter Design
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

File README.markdown

+django-bcrypt
+=============
+
+[You should be using bcrypt](http://codahale.com/how-to-safely-store-a-password/).
+
+django-bcrypt makes it easy to use bcrypt to hash passwords with Django.
+
+Installation and Usage
+----------------------
+
+Install the package with [pip][] and [Mercurial][] or [git][]:
+
+    pip install -e hg+http://bitbucket.org/dwaiter/django-bcrypt#egg=django-ckeditor
+    
+    # or ...
+    
+    pip install -e git://github.com/dwaiter/django-bcrypt.git#egg=django-ckeditor
+
+[pip]: http://pip.openplans.org/
+[Mercurial]: http://hg-scm.org/
+[git]: http://git-scm.com/
+
+Add `django_bcrypt` to your `INSTALLED_APPS`.
+
+That's it.
+
+Any new passwords set will be hashed with bcrypt.  Old passwords will still
+work fine.
+
+Configuration
+-------------
+
+You can set `BCRYPT_ROUNDS` in `settings.py` to change the number of rounds
+django-bcrypt uses.  The default is `12`.
+
+You can change the number of rounds without breaking already-hashed passwords.
+New passwords will use the old number of rounds, and old ones will use the old
+number.
+
+Acknowledgements
+----------------
+
+This is pretty much a packaged-up version of
+[this blog post](http://kfalck.net/2010/12/27/blogi-linodessa-ja-bcrypt-kaytossa)
+for easier use.  It also depends on the
+[py-bcrypt](http://www.mindrot.org/projects/py-bcrypt/) library.

File django_bcrypt/__init__.py

Empty file added.

File django_bcrypt/models.py

+import bcrypt
+from django.contrib.auth.models import User
+from django.conf import settings
+
+
+try:
+    rounds = settings.BCRYPT_ROUNDS
+except AttributeError:
+    rounds = 12
+
+_check_password = User.check_password
+
+def bcrypt_check_password(self, raw_password):
+    if self.password.startswith('bc$'):
+        salt_and_hash = self.password[3:]
+        return bcrypt.hashpw(raw_password, salt_and_hash) == salt_and_hash
+    return _check_password(self, raw_password)
+
+def bcrypt_set_password(self, raw_password):
+    salt = bcrypt.gensalt(rounds)
+    self.password = 'bc$' + bcrypt.hashpw(raw_password, salt)
+
+User.check_password = bcrypt_check_password
+User.set_password = bcrypt_set_password
+
+import os
+from setuptools import setup, find_packages
+
+install_requires = ['py-bcrypt']
+
+README_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.markdown')
+
+description = 'Make Django use bcrypt for hashing passwords.'
+long_description = description
+
+setup(
+    name='django-bcrypt',
+    version='0.9.0',
+    install_requires=install_requires,
+    description=description,
+    long_description=long_description,
+    author='Dumbwaiter Design',
+    author_email='dev@dwaiter.com',
+    url='http://bitbucket.org/dwaiter/django-bcrypt/',
+    packages=['django_bcrypt'],
+)