Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix unicode password migrations

  • Loading branch information...
commit 844e865f22aa90b58c371b1e0a3c3921d0ec2fab 1 parent a764669
@aehlke authored
Showing with 15 additions and 3 deletions.
  1. +1 −1  django_bcrypt/models.py
  2. +14 −2 django_bcrypt/tests.py
View
2  django_bcrypt/models.py
@@ -79,7 +79,7 @@ def bcrypt_check_password(self, raw_password):
if pwd_ok and should_change and is_enabled() and migrate_to_bcrypt():
self.set_password(raw_password)
salt_and_hash = self.password[3:]
- assert bcrypt.hashpw(raw_password, salt_and_hash) == salt_and_hash
+ assert bcrypt.hashpw(smart_str(raw_password), salt_and_hash) == salt_and_hash
self.save()
return pwd_ok
View
16 django_bcrypt/tests.py
@@ -7,6 +7,7 @@
from django import conf
from django.contrib.auth.models import User, UNUSABLE_PASSWORD
from django.test import TestCase
+from django.utils.encoding import smart_str
from django.utils.functional import LazyObject
from django_bcrypt.models import (bcrypt_check_password, bcrypt_set_password,
@@ -53,7 +54,7 @@ def test_change_rounds(self):
class SetPasswordTest(TestCase):
def assertBcrypt(self, hashed, password):
self.assertEqual(hashed[:3], 'bc$')
- self.assertEqual(hashed[3:], bcrypt.hashpw(password, hashed[3:]))
+ self.assertEqual(hashed[3:], bcrypt.hashpw(smart_str(password), hashed[3:]))
def test_set_password(self):
user = User()
@@ -84,7 +85,7 @@ def test_change_rounds(self):
class MigratePasswordTest(TestCase):
def assertBcrypt(self, hashed, password):
self.assertEqual(hashed[:3], 'bc$')
- self.assertEqual(hashed[3:], bcrypt.hashpw(password, hashed[3:]))
+ self.assertEqual(hashed[3:], bcrypt.hashpw(smart_str(password), hashed[3:]))
def assertSha1(self, hashed, password):
self.assertEqual(hashed[:5], 'sha1$')
@@ -98,6 +99,17 @@ def test_migrate_sha1_to_bcrypt(self):
self.assertBcrypt(user.password, 'password')
self.assertEqual(User.objects.get(username='username').password,
user.password)
+
+ def test_migate_unicode(self):
+ user = User(username='username')
+ pw = u'aáåäeéêëoôö'
+ with settings(BCRYPT_MIGRATE=True, BCRYPT_ENABLED_UNDER_TEST=True):
+ _set_password(user, pw)
+ self.assertSha1(user.password, pw)
+ self.assertTrue(bcrypt_check_password(user, pw))
+ self.assertBcrypt(user.password, pw)
+ self.assertEqual(User.objects.get(username='username').password,
+ user.password)
def test_migrate_bcrypt_to_bcrypt(self):
user = User(username='username')
Please sign in to comment.
Something went wrong with that request. Please try again.