Flask-security: Using create_user does not hash the password

Created on 18 Jul 2013  路  3Comments  路  Source: mattupstate/flask-security

Calling register_user will hash the password, as expected, but bypassing it to create a user with the same password will store it in plaintext. This isn't expected and requires your code to depend on the password hashing library explicitly.

Could Flask-Security move the following line from register_user to create_user?

kwargs['password'] = encrypt_password(kwargs['password'])

I can't think of a case where you'd want to intentionally store plaintext, but then again, I haven't been using Flask-Security for very long.

Most helpful comment

Conceptually there is a difference between the Datastore object and the registerable module. The Datastore object is a very simple layer on top of the ORM. It is not concerned with manipulating the data before it is inserted into the database. I prefer this separation of concerns. If you want to create a user with the datastore.create_user function, you can import flask_security.utils.encrypt_password to do what you need before creating the new record in the database.

All 3 comments

Conceptually there is a difference between the Datastore object and the registerable module. The Datastore object is a very simple layer on top of the ORM. It is not concerned with manipulating the data before it is inserted into the database. I prefer this separation of concerns. If you want to create a user with the datastore.create_user function, you can import flask_security.utils.encrypt_password to do what you need before creating the new record in the database.

Ok, I figured it had something to do with Datastore being light-weight. I noticed it does do some slight data manipulation to get the roles right in _prepare_create_user_args, so figured I'd ask. It was just surprising to me initially since you generally don't ever want to store a plaintext password.

Separating the concerns makes sense though.

Thanks for the comment, Matt!

No problem!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mafrosis picture mafrosis  路  7Comments

williamcheng-web picture williamcheng-web  路  4Comments

HarrySky picture HarrySky  路  4Comments

gbrindisi picture gbrindisi  路  5Comments

slippers picture slippers  路  4Comments