[Python] How to Verify WordPress 6.8 hash using Flask

Discussão em 'Python' iniciado por Stack, Julho 6, 2025.

  1. Stack

    Stack Membro Participativo

    I'm looking for guidance on implementing user authentication in a Flask application that integrates with WordPress 6.8, specifically focusing on how to handle the new password hashing methods used by WordPress.

    Cause after updating WordPress to 6.8, it now has different hash than before.

    • then: $P$
    • now: $wp$2y$10$

    My previous code was working fine before updating WordPress to 6.8:

    # ...
    from passlib.hash import phpass

    class Authenticator:

    def __init__(self, flask_app):
    self.flask_app = flask_app

    def authenticate(self, email, password):
    user_password = self.get_user_password(email)
    # user password from DB looks like: $P$.....
    # password looks like (Plain text): "something"
    if not phpass.verify(password, user_password):
    return False, Response.wrong_credentials(self.flask_app.site_url)

    return True, None


    I tried using flask_bcrypt but I got an error: Invalid salt

    # ...
    from flask_bcrypt import Bcrypt

    class Authenticator:

    def __init__(self, flask_app):
    self.flask_app = flask_app
    self.bcrypt = Bcrypt(flask_app)

    def authenticate(self, email, password):
    user_password = self.get_user_password(email)
    # user password in DB looks like: $WP$2y$10$...
    # password looks like (Plain text): "something"
    try:
    if not self.bcrypt.check_password_hash(user_password, password):
    return False, Response.wrong_credentials(self.flask_app.site_url)
    except Exception as e:
    print(e) # it throw error: Invalid Salt
    return True, None

    Continue reading...

Compartilhe esta Página