def login(self, email, password): try: salt = self._get_salt_from_db(email, True) hashed_password = crypto.create_hash(password, salt) result = self._db_connection.execute_scalar( "SELECT id FROM users WHERE email = %s AND password = %s LIMIT 1", (email, hashed_password) ) finally: self._db_connection.close() return result is not None
def create(self, email, password): if self.exists(email): raise EmailAlreadyInUseError(email) if len(email) > 100: raise EmailTooLongError(email, 100) activation_token = crypto.create_activation_token() salt = crypto.create_salt() hashed_password = crypto.create_hash(password,salt) self._db_connection.execute_non_query( ("INSERT INTO users (email, password, salt, activation_token, activation_token_requested, created)" "VALUES (%s, %s, %s, %s, NOW(), NOW())"), (email, hashed_password, salt, activation_token) ) return activation_token
def test_create_hash(self): salt = crypto.create_salt() self.assertEqual( crypto.create_hash("MESSAGE", salt), crypto.create_hash("MESSAGE", salt) )