Commits

Frank Smit committed 652e01f

Switched order of bcrypt.Bcrypt.check arguments.

  • Participants
  • Parent commits 02fb82b

Comments (0)

Files changed (3)

 syntax: regexp
 
+.*?\.sublime-project
+.*?\.sublime-workspace
 \.hgignore
 ^py2-env/
 ^py3-env/

cryptacular/bcrypt/__init__.py

 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 # THE SOFTWARE.
 
-__all__ = ['BCRYPTPasswordManager']
+__all__ = ['Bcrypt']
 
 
 import os
 from cryptacular.core import _cmp, check_unicode
 
 
-class BCRYPTPasswordManager(object):
+class Bcrypt(object):
 
     _scheme = 'BCRYPT'
     _prefix = '$2a$'
 
         return encoded
 
-    def check(self, encoded, text):
+    def check(self, text, encoded):
         '''Check a bcrypt password hash against a password.
         '''
         if not self.match(encoded):

tests/test_bcrypt.py

 import unittest
-from cryptacular.bcrypt import BCRYPTPasswordManager
+from cryptacular.bcrypt import Bcrypt
 
 
 try:
     snowpass = unicode('hashy the \N{SNOWMAN}')
 
     def setUp(self):
-        self.bcrypt = BCRYPTPasswordManager()
+        self.bcrypt = Bcrypt()
 
     def test_none_1(self):
         self.assertRaises(TypeError, self.bcrypt.encode, None)
 
     def test_none_2(self):
-        self.assertRaises(TypeError, self.bcrypt.check, None, 'xyzzy')
+        self.assertRaises(TypeError, self.bcrypt.check, 'xyzzy', None)
 
     def test_none_3(self):
         hash = self.bcrypt.encode('xyzzy')
-        self.assertRaises(TypeError, self.bcrypt.check, hash, None)
+        self.assertRaises(TypeError, self.bcrypt.check, None, hash)
 
     def test_badhash(self):
         self.assertFalse(
             self.bcrypt.check(
-                '$p5k2$400$ZxK4ZBJCfQg=$kBpklVI9kA13kP32HMZL0rloQ1M=',
-            self.snowpass))
+                self.snowpass,
+                '$p5k2$400$ZxK4ZBJCfQg=$kBpklVI9kA13kP32HMZL0rloQ1M='
+            ))
 
     def test_shorthash(self):
         def match(hash):
             return True
-        bcrypt = BCRYPTPasswordManager()
+        bcrypt = Bcrypt()
         bcrypt.match = match
         short_hash = bcrypt.encode(self.snowpass)[:28]
-        self.assertRaises(ValueError, bcrypt.check, short_hash, self.snowpass)
+        self.assertRaises(ValueError, bcrypt.check, self.snowpass, short_hash)
 
     def test_too_few_rounds(self):
         self.assertRaises(ValueError, self.bcrypt.encode, self.snowpass, rounds=1)
     def test_valid_hash_1(self):
         hash = self.bcrypt.encode(self.snowpass)
         self.assertTrue(self.bcrypt.match(hash))
-        self.assertTrue(self.bcrypt.check(hash, self.snowpass))
+        self.assertTrue(self.bcrypt.check(self.snowpass, hash))
         self.assertEqual(len(hash), 60)
 
     def test_valid_hash_2(self):
         password = "xyzzy"
         hash = self.bcrypt.encode(password)
-        self.assertTrue(self.bcrypt.check(hash, password))
-        self.assertTrue(self.bcrypt.check(unicode(hash), password))
+        self.assertTrue(self.bcrypt.check(password, hash))
+        self.assertTrue(self.bcrypt.check(password, unicode(hash)))
         self.assertFalse(self.bcrypt.check(password, password))
         self.assertNotEqual(self.bcrypt.encode(password),
             self.bcrypt.encode(password))
         hash = self.bcrypt.encode(password, rounds=4)
-        self.assertTrue(self.bcrypt.check(hash, password))
+        self.assertTrue(self.bcrypt.check(password, hash))
 
 
 if __name__ == '__main__':