当前位置: 首页>>代码示例>>Python>>正文


Python pyotp.random_base32方法代码示例

本文整理汇总了Python中pyotp.random_base32方法的典型用法代码示例。如果您正苦于以下问题:Python pyotp.random_base32方法的具体用法?Python pyotp.random_base32怎么用?Python pyotp.random_base32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyotp的用法示例。


在下文中一共展示了pyotp.random_base32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mfa_get_secret

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def mfa_get_secret(username):

    #secret=pyotp.random_base32()

    conn = sqlite3.connect('db_users.sqlite')
    conn.set_trace_callback(print)
    conn.row_factory = sqlite3.Row
    c = conn.cursor()

    #c.execute("UPDATE users SET mfa = ? WHERE username = ?", (secret, username,))
    user = c.execute("SELECT * FROM users WHERE username = ?", (username, )).fetchone()

    if user:
        return user['mfa_secret'] #True
    else:
        return False 
开发者ID:fportantier,项目名称:vulpy,代码行数:18,代码来源:libmfa.py

示例2: mfa_reset_secret

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def mfa_reset_secret(username):

    secret=pyotp.random_base32()

    conn = sqlite3.connect('db_users.sqlite')
    conn.set_trace_callback(print)
    conn.row_factory = sqlite3.Row
    c = conn.cursor()

    #c.execute("UPDATE users SET mfa = ? WHERE username = ?", (secret, username,))
    #user = c.execute("SELECT * FROM users WHERE username = ?", (username, )).fetchone()
    c.execute("UPDATE users SET mfa_secret = ? WHERE username = ?", (secret, username))
    conn.commit()

    #if user:
    #    return user['mfa_secret'] #True
    #else:
    return False 
开发者ID:fportantier,项目名称:vulpy,代码行数:20,代码来源:libmfa.py

示例3: get_qrcode

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def get_qrcode(user):
    if not user.qrcode:
        user.qrcode = pyotp.random_base32()
        user.save()
    file_name = str(aes.encrypt(user.qrcode), encoding='utf-8')
    file = settings.QCODE_ROOT+'/'+file_name+'.png'
    if not os.path.exists(file):
        data = pyotp.totp.TOTP(user.qrcode).provisioning_uri(user.username, issuer_name="devEops")
        qr = QRCode(
            version=1,
            error_correction=constants.ERROR_CORRECT_L,
            box_size=6,
            border=4,)
        try:
            qr.add_data(data)
            qr.make(fit=True)
            img = qr.make_image()
            img.save(file)
            return '/media/qrcode/' + file_name + '.png'
        except Exception as e:
            return '/media/qrcode/' + file_name + '.png'
    else:
        return '/media/qrcode/' + file_name + '.png' 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:25,代码来源:user.py

示例4: refresh_secret

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def refresh_secret(self, secret_path: Optional[str] = None) -> Response:
        """
        Refresh the secret token for key generation given a secret path.

        :param secret_path: Secret path to refresh (default: default configured path).
        """

        secret_path = secret_path or self.secret_path
        assert secret_path, 'No secret_path configured'

        os.makedirs(os.path.dirname(os.path.abspath(os.path.expanduser(secret_path))), exist_ok=True)
        secret = pyotp.random_base32()
        with open(secret_path, 'w') as f:
            f.writelines([secret])
        os.chmod(secret_path, 0o600)
        return secret 
开发者ID:BlackLight,项目名称:platypush,代码行数:18,代码来源:otp.py

示例5: test_two_factor_auth_user

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def test_two_factor_auth_user(app):
    with app.app_context():
        user = User(username="TEST_FACTOR_USER", password="TEST_USER_PASSWORD")
        ug = Group(name="TEST_FACTOR_USER", user_group=True, members=[user])
        secret = pyotp.random_base32()
        auth = TwoFactorAuth(user=user, enabled=True)
        auth.secret_key = secret
        otp_generator = partial(get_two_factor_code, secret)
        db.session.add(user)
        db.session.add(auth)
        db.session.add(ug)
        db.session.commit()
        backup_codes = generate_backup_codes()
        for code in backup_codes:
            backup = TwoFactorBackup(auth_id=auth.user_id)
            backup.backup_code = code
            db.session.add(backup)
        db.session.commit()
        return TestTwoFactorUser(
            user.id, user.username, "TEST_USER_PASSWORD", otp_generator, backup_codes
        ) 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:23,代码来源:conftest.py

示例6: mfa_setup

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def mfa_setup():
    if current_user.enable_otp:
        flash("you have already enabled MFA", "warning")
        return redirect(url_for("dashboard.index"))

    otp_token_form = OtpTokenForm()

    if not current_user.otp_secret:
        LOG.d("Generate otp_secret for user %s", current_user)
        current_user.otp_secret = pyotp.random_base32()
        db.session.commit()

    totp = pyotp.TOTP(current_user.otp_secret)

    if otp_token_form.validate_on_submit():
        token = otp_token_form.token.data.replace(" ", "")

        if totp.verify(token) and current_user.last_otp != token:
            current_user.enable_otp = True
            current_user.last_otp = token
            db.session.commit()
            flash("MFA has been activated", "success")

            return redirect(url_for("dashboard.recovery_code_route"))
        else:
            flash("Incorrect token", "warning")

    otp_uri = pyotp.totp.TOTP(current_user.otp_secret).provisioning_uri(
        name=current_user.email, issuer_name="SimpleLogin"
    )

    return render_template(
        "dashboard/mfa_setup.html", otp_token_form=otp_token_form, otp_uri=otp_uri
    ) 
开发者ID:simple-login,项目名称:app,代码行数:36,代码来源:mfa_setup.py

示例7: set_TFA_secret

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def set_TFA_secret(self):
        secret = pyotp.random_base32()
        self._TFA_secret = encrypt_string(secret) 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:5,代码来源:user.py

示例8: edit_profile

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def edit_profile():
    """Edit profile function allows the user to modify their about me section."""
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        user_name = User.query.filter_by(username=current_user.username).first()
        if user_name is None:
            render_error_page_template(404)
        if form.otp_token_checkbox.data:
            if user_name.otp_secret:
                current_user.otp_secret = user_name.otp_secret
            else:
                current_user.otp_secret = pyotp.random_base32()
            db.session.commit()
            url = pyqrcode.create(user_name.get_totp_uri())
            stream = BytesIO()
            url.svg(stream, scale=3)
            return render_template('two-factor-setup.html'), 200, {
                'Cache-Control': 'no-cache, no-store, must-revalidate',
                'Pragma': 'no-cache',
                'Expires': '0'}
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
        if form.otp_token_checkbox:
            if form.otp_token_checkbox.data:
                form.otp_token.data = current_user.otp_token
        else:
            form.otp_token_checkbox = current_user.otp_token_checkbox
    else:
        for error in form.errors:
            flash(str(form.errors[error][0]), 'error')
    return render_template('edit_profile.html', title=_('Edit Profile'), form=form) 
开发者ID:AUCR,项目名称:AUCR,代码行数:36,代码来源:routes.py

示例9: set_otp_secret

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def set_otp_secret(self):
        """Set two factor token for user."""
        if self.otp_secret is None:
            # generate a random secret
            self.otp_secret = pyotp.random_base32() 
开发者ID:AUCR,项目名称:AUCR,代码行数:7,代码来源:models.py

示例10: mfa_enable

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def mfa_enable(username):

    #secret=pyotp.random_base32()

    conn = sqlite3.connect('db_users.sqlite')
    conn.set_trace_callback(print)
    conn.row_factory = sqlite3.Row
    c = conn.cursor()

    #c.execute("UPDATE users SET mfa = ? WHERE username = ?", (secret, username,))
    c.execute("UPDATE users SET mfa_enabled = 1 WHERE username = ?", (username,))
    conn.commit()

    return True 
开发者ID:fportantier,项目名称:vulpy,代码行数:16,代码来源:libmfa.py

示例11: get

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def get(self, request, *args, **kwargs):
        profile = self.profile
        if not profile.totp_key:
            profile.totp_key = pyotp.random_base32(length=32)
            profile.save(update_fields=['totp_key'])
        if not profile.scratch_codes:
            profile.generate_scratch_codes()
        return self.render_to_response(self.get_context_data()) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:10,代码来源:two_factor.py

示例12: generate_scratch_codes

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def generate_scratch_codes(self):
        codes = [pyotp.random_base32(length=16) for i in range(settings.DMOJ_SCRATCH_CODES_COUNT)]
        self.scratch_codes = json.dumps(codes)
        self.save(update_fields=['scratch_codes'])
        return codes 
开发者ID:DMOJ,项目名称:online-judge,代码行数:7,代码来源:profile.py

示例13: generate_otp_hash

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def generate_otp_hash(self):
        try:
            import pyotp
            return pyotp.random_base32()
        except ImportError:
            print("You must install pyotp to use `generate_otp_hash`.")
            print("pip install pyotp")
            return None 
开发者ID:IntuitiveWebSolutions,项目名称:PyWebRunner,代码行数:10,代码来源:WebRunner.py

示例14: __init__

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def __init__(self, *args, **kwargs):
        self.user = kwargs.pop("user")
        super().__init__(*args, **kwargs)
        self.initial_secret = pyotp.random_base32()
        self.fields["secret"].initial = self.initial_secret 
开发者ID:zentralopensource,项目名称:zentral,代码行数:7,代码来源:forms.py

示例15: post_create

# 需要导入模块: import pyotp [as 别名]
# 或者: from pyotp import random_base32 [as 别名]
def post_create(cls, sender, instance, created, *args, **kwargs):  # pylint: disable=unused-argument
        if created:
            instance.secret = pyotp.random_base32()
            instance.save() 
开发者ID:wncc,项目名称:instiapp-api,代码行数:6,代码来源:models.py


注:本文中的pyotp.random_base32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。