database.py 文件源码

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

项目:Gnome-Authenticator 作者: bil-elmoussaoui 项目源码 文件源码
def add_account(self, name, secret_code, image):
        """
            Add an account to accounts table
            :param name: (str) account name
            :param secret_code: (str) ASCII Secret code
            :param image: image path or icon name
            :return:
        """
        encrypted_secret = sha256(secret_code.encode('utf-8')).hexdigest()
        t = (name, encrypted_secret, image,)
        query = "INSERT INTO accounts (name, secret_code, image) VALUES (?, ?, ?)"
        try:
            GK.create_sync("org.gnome.Authenticator", None)
            attr = GK.Attribute.list_new()
            GK.Attribute.list_append_string(attr, 'id', encrypted_secret)
            GK.Attribute.list_append_string(attr, 'secret_code', secret_code)
            GK.item_create_sync("org.gnome.Authenticator", GK.ItemType.GENERIC_SECRET, repr(encrypted_secret), attr,
                                secret_code, False)
            self.conn.execute(query, t)
            self.conn.commit()
            uid = self.get_latest_id()
            return [uid, name, encrypted_secret, image]
        except Exception as e:
            logging.error("SQL: Couldn't add a new account : %s ", str(e))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号