DbClass.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:Lightz 作者: MathieuBonteHowest 项目源码 文件源码
def register(self, username, password, code):
        #Query met parameters
        sqlQuery = "Select * from tbl_users WHERE username = '{param1}'"
        sqlCommand = sqlQuery.format(param1=username)
        self.__cursor.execute(sqlCommand)
        result = self.__cursor.fetchone()

        if int(code) == 25081998:
            if result:
                message = "Error: Deze gebruiker bestaat al"
            else:
                pwd_bytes = password
                salt_bytes = os.urandom(16)
                hash_bytes = hashlib.pbkdf2_hmac('sha256', pwd_bytes, salt_bytes, 100000)
                salt_string = binascii.hexlify(salt_bytes).decode('utf-8')
                hash_string = binascii.hexlify(hash_bytes).decode('utf-8')

                sqlQuery2 = "INSERT INTO tbl_users (username, pwd_hash, pwd_salt) VALUES ('{param1}', '{param2}', '{param3}')"
                sqlCommand2 = sqlQuery2.format(param1=username, param2=hash_string, param3=salt_string)

                self.__cursor.execute(sqlCommand2)
                self.__connection.commit()
                self.__cursor.close()

                message = "Succesvol geregistreerd"
        else:
            message = "Error: Foute code"

        return message
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号