LU06.L08 - Passwort-Hashing in der Todo-Liste

userDao.py
    def add_user(self, user):
        hashed_pw = bcrypt.hashpw(user.password.encode('utf-8'), bcrypt.gensalt())
        self.cursor.execute("INSERT INTO users (username, email, password) VALUES (?, ?, ?)",
                            (user.username, user.email, hashed_pw))
        self.conn.commit()
userBlueprint.py
def login():
    data = request.get_json()
    user = user_dao.get_user_by_username(data['username'])
    print(user.password)
    if user and bcrypt.checkpw(data['password'].encode('utf-8'), user.password):
        login_user(user)
        return jsonify({'success': True}), 200
    return jsonify({'error': 'Invalid username or password'}), 401
requirements.txt
bcrypt==4.0.1
  • modul/m323/learningunits/lu06/loesungen/hash.txt
  • Zuletzt geändert: 2024/03/28 14:07
  • von 127.0.0.1