Пример #1
0
    def register_user(self, first_name, last_name, username, raw_password):
        """Register player to the database with username 
        and encrypted password"""
        if self.username_exist(username):
            return False

        algo = 'sha1'
        salt = encryption.get_hexdigest(algo, str(random.random()),
                                        str(random.random()))[:5]
        hsh = encryption.get_hexdigest(algo, salt, raw_password)
        password = '******'.format(algo, salt, hsh)

        self.db.insert('user_table', {
            'first_name': first_name,
            'last_name': last_name,
            'username': username,
            'password': password,
            'role': 'normal'
        })
        return True
Пример #2
0
 def login(self, username, password):
     """Check user login data, return true if the
     data is matched with database"""
     user_password = self.db.getOne(
         'user_table',
         ['password'],
         ('username=%s', [username])
     )
     if user_password:
         algo, salt, hsh = user_password[0].split('$')
         return True if hsh == encryption.get_hexdigest(algo,
                                                        salt, password) else False
     else:
         return False