maxcountryman / flask-bcrypt

Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application.

Home Page:http://readthedocs.org/docs/flask-bcrypt/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fail when try to authenticate

xmnlab opened this issue · comments

Hi, I've realized that when I create a user with bcrypt password, the check password works just for that current day ... the next day .. the password doesn't match.

What am I doing wrong?

Thank you.

Can you provide the code you're using to encrypt and save passwords as well as the code to check them?

I'm using flask with sqlalchemy and wtforms from cookiecutter-flask

This is the code of my model class (resumed):

class User(UserMixin, SurrogatePK, Model):
    __tablename__ = 'users'
    username = Column(db.String(80), unique=True, nullable=False)
    password = Column(db.String(128), nullable=True)

    def __init__(self, **kwargs):
        db.Model.__init__(self, **kwargs)

    def check_password(self, value):
        print(self.password)  # TODO: remove it.
        print(bcrypt.hashpw(value, self.password))  # TODO: remove it.
        return flask_bcrypt.check_password_hash(self.password, value)

    @classmethod
    def crypt(cls, value):
        return flask_bcrypt.generate_password_hash(value)

Without more context, it's hard to see what's going on. Nothing in the code you provided should be time dependent.

The method to save the data is that:

model = User.get_by_id(id)
form = UserForm(request.form, model)

if form.validate_on_submit():
    form.populate_obj(model)
    model.save()

but, it doesn't have any time dependency ...

it's so weird ..

how can I find more information about the parameters used for theses methods in my programming ...
I don't know ... maybe this can be some configuration ...

if you have some idea ... i will appreciate a lot.

my best,

If you'd like to email me a sample application that demonstrates this problem I can try to look at it more. As you said, there are no obvious time-dependent components here.

ok, I will do it! I will create a new project using cookiecutter .. and I will check tomorrow if i will have the same problem with a new empty project, next I will contact you to talk about the results.

my best,

after I changed to virtualenv the problem was solved! thank you!