def qrcode_from_totp(secret, label, issuer):
if type(secret) != six.text_type:
raise Exception('secret must be of type unicode, not {}'.format(type(secret)))
if type(label) != six.text_type:
raise Exception('label must be of type unicode, not {}'.format(type(label)))
try:
import pyqrcode
except ImportError:
raise Exception('pyqrcode not installed')
import io
buffer = io.BytesIO()
data = pyqrcode.create(u'otpauth://totp/{}?secret={}&issuer={}'.format(label, secret, issuer))
data.svg(buffer, omithw=True)
return buffer.getvalue()
#
# The following code is adapted from the pbkdf2_bin() function
# in here https://github.com/mitsuhiko/python-pbkdf2
# Copyright 2011 by Armin Ronacher. Licensed under BSD license.
# https://github.com/mitsuhiko/python-pbkdf2/blob/master/LICENSE
#
评论列表
文章目录