auth.py 文件源码

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

项目:pyom_mud 作者: bodrich 项目源码 文件源码
def random_base32_token(length: int=16, rng=random.SystemRandom(),
                        charset='ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'):
    """
    This method just provides a quick way to obtain a proper key to
    use for a 2-factor authentication secret key.

    :param length: Normally 16
    :type length: int
    :param rng: Normally, the system RNG
    :type rng: method
    :param charset: The base32 character set
    :type charset: str
    :return: A 16-character base32 encoded token
    :rtype: str
    """
    token = ''.join(rng.choice(charset) for i in range(length))
    return '-'.join((token[0:4], token[4:8], token[8:12], token[12:16]))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号