Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PasswordType commit does nothing when verify_and_update is triggered. #49

Closed
Flyflo opened this issue Nov 9, 2013 · 2 comments
Closed

Comments

@Flyflo
Copy link

Flyflo commented Nov 9, 2013

Committing a PasswordType that has been updated by the verify_and_update method because it's using a deprecated scheme doesn't work correctly for me.

After comparing the password with the correct one, the value is actually updated with the new scheme but when I commit my object, the change isn't reflected to the DB.

Here's a minimal code to reproduce the behavior (using Python 3.3.2):

from sqlalchemy import create_engine, Column, Integer, event
from sqlalchemy.orm import sessionmaker, mapper
from sqlalchemy.ext.declarative import declarative_base
from passlib.hash import md5_crypt
from sqlalchemy_utils import Password, PasswordType, coercion_listener

sql_engine = create_engine('sqlite:///testdb.sqlite')
Session = sessionmaker(bind=sql_engine)
session = Session()
Base = declarative_base()
event.listen(mapper, 'mapper_configured', coercion_listener)


class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, primary_key=True)

    password = Column(PasswordType(
        schemes=[
            'pbkdf2_sha512',
            'md5_crypt'
        ],

        deprecated=['md5_crypt']
    ))

Base.metadata.drop_all(sql_engine)
Base.metadata.create_all(sql_engine)

user = User()
session.add(user)

user.password = Password(md5_crypt.encrypt('b').encode('utf-8'))
session.commit()

print(user.password.hash)           # The md5 hash
print(user.password == 'b')         # True and update the hash
print(user.password.hash)           # The hash is now pbkdf2_sha512
session.commit()                    # Nothing changes

user = session.query(User).get(1)   # Get the previous object from the database
print(user.password.hash)           # The password is still a md5 hash instead of pbkdf2_sha512

Is this the correct behavior or am I missing something ?

@mehcode
Copy link
Collaborator

mehcode commented Nov 21, 2013

Okay; @Flyflo, that should have fixed it. Can you install from master and see if it works for you?

@Flyflo
Copy link
Author

Flyflo commented Nov 22, 2013

It seems to work as expected.
Thank you for the fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants