Flask-Bcrypt ValueError:无效的ROUNDS

时间:2016-06-12 01:33:50

标签: ubuntu flask bcrypt password-hash

我遇到了Flask-Bcrypt的问题,当我尝试加密密码时,它会在网站上出现500错误。我使用的是ubuntu 14.04 / Python 3.5。

This is the error in apache error.log

这是我的模特:

class User(db.Model, UserMixin):
id = db.Column(db.Integer(), primary_key=True)
username = db.Column(db.String(255), unique=True)
email = db.Column(db.String(255), unique=True)
password = db.Column(db.String(255), nullable=False)
settings = db.relationship('UserSettings', backref='user', lazy='dynamic')
following = db.relationship('User',
    secondary = follow,
    primaryjoin = (follow.c.follower_id == id),
    secondaryjoin = (follow.c.following_id == id),
    backref = db.backref('follow'),
lazy='dynamic')
created =  db.Column(db.DateTime())

@property
def is_authenticated(self):
    return True

@property
def is_active(self):
    return True

@property
def is_anonymous(self):
    return False

def get_id(self):
    try:
        return unicode(self.id)  # python 2
    except NameError:
        return str(self.id)  # python 3

def __init__(self, username, email, password, created):
    self.username = username
    self.email = email
    self.password = bcrypt.generate_password_hash(password).decode('utf-8')
    self.created = created

def __repr__(self):
    return self.username

这是我的观点:

    @app.route("/register", methods=['GET','POST'])
def register():
    pageType="register"
    error = None
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('settings'))
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        Suser = User.query.filter_by(username=request.form['username'].lower()).first()
        if Suser is not None:
            error = "Username is already taken."
        else:
            user = User(
                username=remove_html_tags(form.username.data).lower(),
                email=remove_html_tags(form.email.data).lower(),
                password= form.password.data,
                created=datetime.now()

            )
            db.session.add(user)
            user.follow.append(user)
            user.settings.append(UserSettings(displayname=remove_html_tags(form.displayname.data)))
            db.session.commit()
            login_user(user)
            return redirect(url_for('dash'))
    return render_template("register.html", form=form, title="Register", error=error, page=pageType)

我能够在localhost中使用它。 我试过了self.password = bcrypt.generate_password_hash(password, 14).decode('utf-8')

但仍然出现错误。

0 个答案:

没有答案