def test_encrypt_password(self): from tornado_utils import encrypt_password p = encrypt_password('', log_rounds=12) p2 = encrypt_password('', log_rounds=12) self.assertNotEqual(p, p2) self.assertTrue(isinstance(p, unicode)) self.assertTrue('$bcrypt$' in p) # simulate what the User class's check_password does import bcrypt p = 'secret' r = encrypt_password(p, log_rounds=12) hashed = r.split('$bcrypt$')[-1].encode('utf8') self.assertEqual(hashed, bcrypt.hashpw(p, hashed))
def test_create_user(self): user = self.db.User() user.username = u'peterbe' assert user.add_date assert user.modify_date user.save() inst = self.db.users.User.one() assert inst.username inst.password = encrypt_password('secret') inst.save() self.assertFalse(inst.check_password('Secret')) self.assertTrue(inst.check_password('secret'))
def set_password(self, raw_password, encrypt=False): if encrypt: from tornado_utils import encrypt_password raw_password = encrypt_password(raw_password) self.password = raw_password
def set_password(self, raw_password): self.password = encrypt_password(raw_password)