mitsuhiko/flask-sqlalchemy — Issue #71: Bcrypt data being changed on insert into SQLite
Author: kura
Created: 2012-02-14 16:29:33+00:00
State: open

I have an implementation of Mozilla's password policy in Python that creates an HMAC key, uses b64 encoded version of it within bcrypt to create an encrypted password.

When I create one of these manually and insert it in to SQLite directly, it all works fine and is as expected.

When I insert this in to the database using a model and db.session the value in SQLite is not the value that was inserted.

i.e.

db.session.add(User("kura", "bcrypt$2a$12$7kmx7ZdtXwUSsfdfBxp/ouhGnWhPIylCZUYhifnIaMcyM4hkNg9Jq$2012-02-14", "kura@tangentlabs.co.uk", "Kura"))
db.session.commit()

When I query that result, instead of getting the value I inserted I get

bcrypt$2a$12$RGkcKVIM6.Crv.ZIzVn5EuxN6OYEHic2zO8IBhCHVev0WT7F0klKu$2012-02-14

Querying SQLite directly using the Linux binary shows that the second (incorrect) value is the one stored.

If I change that value manually using the SQLite binary and then requery from Python it is correct.

Any ideas why this would be the case?