Forums

BCyrpt

Hi all,
From what I've gathered, flask bcyrpt cannot be installed due to the fact it extends upon the root flask module. Would there be any get around/alternatives I could use?
Thanks,
Aj

How about...

from werkzeug.security import generate_password_hash, check_password_hash

''' creates a salted hash'''
class User(object):

    def __init__(self, username, password):
        self.username = username
        self.set_password(password)

    def set_password(self, password):
        self.pw_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.pw_hash, password)

Then to check the user password against the hash use...

check_password_hash(hash, password)

see more here http://flask.pocoo.org/snippets/54/

Hmm my suggestion might not be as secure so depends what you are storing I guess