after use generate_password_hash(password), password sequencethe is not in database Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of after use generate_password_hash(password), password sequencethe is not in database without wasting too much if your time.

The question is published on by Tutorial Guruji team.

i am studying flask web, and have some question

@auth.route('/register', methods=['GET', 'POST'])
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user=User(email=form.email.data,username=form.username.data, 
                  password_hash=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('you can now login')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)


class User(UserMixin, db.Model): 
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.Integer, unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
    password_hash = db.Column(db.String(128))
    @property
    def password(self):
        raise AttributeError('password is not a readable attribute')

    @password.setter
    def password(self, password):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password) 

    def __repr__(self):
        return '<user %r>' % self.username

register image

database image

When I enter the account password registration, the password is 16. but The password of the database is also 16, not the sequence of the password.

i can’t understand

Answer

Instead of

user=User(email=form.email.data,username=form.username.data, 
              password_hash=form.password.data)

Try this

user=User(email=form.email.data,username=form.username.data, 
              password=form.password.data)

Or if you want to be 100% sure then

user=User(email=form.email.data,username=form.username.data)
user.password = form.password.data
We are here to answer your question about after use generate_password_hash(password), password sequencethe is not in database - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji