I'm working on the register section of application.py. When I've typed in the username and password and hit register, I get an internal server error. I'm assuming that pbkdf2:sha256:150000$uJ2F7qcX$ef0f0071fa6925727e1c444e4072b8ea3e519ed680f317e53c05acf09604ec1e is the hashed password, but I'm not 100% sure. Any help fixing this error would be really appreciated. Thank you!

@app.route("/register", methods=["GET", "POST"])
def register():
    """Register user"""
    if request.method == "POST":
        if not request.form.get("username"):
            return apology("must provide username!")
        elif not request.form.get("password"):
            return apology("must provide password")
        elif not request.form.get("password_again"):
            return apology("must provide password confirmation")
        elif request.form.get("password") != request.form.get("password_again"):
            return apology("Sorry, passwords didn't match. Try again.")
        hashed_password = generate_password_hash(request.form.get("password"))
        result = db.execute("INSERT INTO USERS (username, hash) VALUES (:username :hash)", username=request.form.get("username"), hash=hashed_password)
        if not result:
            return apology("That username has already been taken. Sorry!")
        rows = db.execute("SELECT * FROM users WHERE username = :username", username = request.form.get("username"))
        session["user_id"] = rows[0]["id"]
        return redirect("/")
        return render_template("register.html")
DEBUG:cs50:INSERT INTO USERS (username, hash) VALUES ('testing' 'pbkdf2:sha256:150000$uJ2F7qcX$ef0f0071fa6925727e1c444e4072b8ea3e519ed680f317e53c05acf09604ec1e')
ERROR:application:Exception on /register [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/pset8/finance/application.py", line 133, in register
    result = db.execute("INSERT INTO USERS (username, hash) VALUES (:username :hash)", username=request.form.get("username"), hash=hashed_password)
  File "/usr/local/lib/python3.7/site-packages/cs50/sql.py", line 21, in decorator
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/cs50/sql.py", line 372, in execute
    raise e
RuntimeError: near "'pbkdf2:sha256:150000$uJ2F7qcX$ef0f0071fa6925727e1c444e4072b8ea3e519ed680f317e53c05acf09604ec1e'": syntax error
INFO:werkzeug: - - [15/Aug/2020 23:17:14] "POST /register HTTP/1.0" 500 -
INFO:werkzeug: - - [15/Aug/2020 23:17:14] "GET /static/styles.css HTTP/1.0" 200 -

Recheck line result = db.execute("INSERT INTO USERS (username, hash) VALUES (:username :hash); the values of an INSERT should be separated with commas a la INSERT INTO table_name (column1, column2, column3, ...) VALUES (:placeholder1, :placeholder2, :placeholder3, ...). Moreover, the table names should ideally follow consistent letter case.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .