python - invalid salt still even when using decode utf -
can tell me im doing wrong, keep getting invalid salt, want hash password using bcrypt. here code
views.py
@app.route('/login',methods=['get','post']) def login(): if request.method == 'get': return render_template('login.html') username = request.form['username'] password =request.form['password'] user = user.query.filter_by(username=username).first() if user , bcrypt.check_password_hash(user.password, request.form['password']): login_user(user) session['logged_in'] = true flash('logged in successfully') return redirect(request.args.get('next') or url_for('index')) else: flash('invalid username or password') return redirect(url_for('login'))
models.py
from app import db, bcrypt class user(db.model): __tablename__ = "users" id = db.column(db.integer, primary_key=true) username = db.column(db.string(80), unique=true) password = db.column(db.string(20), unique=true) def __init__(self, username, password): self.username = username pwhash = bcrypt.generate_password_hash(password.encode('utf8'), bcrypt.gensalt()) self.password = pwhash.decode('utf8') def is_authenticated(self): return true def is_active(self): return true def is_anonymous(self): return false def get_id(self): return (self.id) def __repr__(self): return '<user %r>' % self.username
i think did right, used salt, used decode utf, keep getting invalid salt, recommendations guys
Comments
Post a Comment