Coder Social home page Coder Social logo

How to add Authenticator about moonraker HOT 2 OPEN

SlimRG avatar SlimRG commented on May 29, 2024 1
How to add Authenticator

from moonraker.

Comments (2)

SlimRG avatar SlimRG commented on May 29, 2024

Adding a little, but I don't know more about your code.
I know python only a little(
But you can add

    def __init__(self, config: ConfigHelper) -> None:
        """
        Initialize with a storage mechanism for user-specific secrets.
        user_secret_storage should be a dictionary or a database that maps usernames to secret keys.
        """
        self.user_secret_storage = user_secret_storage

    def generate_secret(self) -> str:
        """
        Generate a new secret key that can be saved for a user.
        Typically, this would be done during the setup process of 2FA.
        """
        return pyotp.random_base32()

    def get_uri_for_qr(self, username: str, issuer_name: str) -> str:
        """
        Generate a URI that can be encoded into a QR code and scanned by Google Authenticator.
        issuer_name is the name of the organization providing the 2FA.
        """
        secret = self.user_secret_storage.get(username)
        if not secret:
            raise ValueError("User does not have a secret key set up.")
        return pyotp.TOTP(secret).provisioning_uri(username, issuer_name=issuer_name)

    def verify_code(self, username: str, code: str) -> bool:
        """
        Verify the TOTP code entered by the user.
        Returns True if the code is correct, False otherwise.
        """
        secret = self.user_secret_storage.get(username)
        if not secret:
            raise self.server.error("User does not have a secret key set up.")
        
        totp = pyotp.TOTP(secret)
        return totp.verify(code)

from moonraker.

SlimRG avatar SlimRG commented on May 29, 2024

I don't like python lang, but made support for you)

#844

from moonraker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.