0

I implemented the register function for pset7. It went to the register page that I had implemented. I gave the required credentials and clicked Register. But instead of registering with the credentials and redirecting me to the home page, it showed a HTML page with this text:

***Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application***

I went back to the IDE and looked for any error messages. And I saw this:

 *File "/home/ubuntu/workspace/pset7/finance/application.py", line 131, in register
    db.execute("INSERT INTO users WHERE username = :username AND hash = :hash", username = request.form.get("username"), hash = pwd_context.encrypt(request.form.get("password")))
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/passlib/utils/decor.py", line 190, in wrapper
    warn(msg % tmp, DeprecationWarning, stacklevel=2)
**DeprecationWarning: the method passlib.context.CryptContext.encrypt() is deprecated as of Passlib 1.7, and will be removed in Passlib 2.0, use CryptContext.hash() instead.**
INFO:werkzeug:10.240.1.50 - - [21/May/2018 06:11:13] "POST /register HTTP/1.1" 500 -*

The part I formatted in bold is what I am worried about. It tells me to use CryptContextHash() instead of pwd_context.encrypt() as mentioned in the short. Should I use CryptContextHash? Are there any changes I have to make any changes to login doing so? Or have I made an error in my code:

***# register user

        else:

            # add user's data to database

            db.execute("INSERT INTO users WHERE username = :username AND hash = :hash", username = request.form.get("username"), hash = pwd_context.encrypt(request.form.get("password")))

            # sign user in

            session["user_id"] = rows[0]["id"]

            # redirect user to homepage

            return redirect(url_for("index"))***
0

clearly to the function to generate the hash is in disuse, we must look for another alternative, for me the following code worked well:

 hash = generate_password_hash(request.form.get("password"), method='pbkdf2:sha256', salt_length=8)

 db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)", username=request.form.get("username"), hash = hash)
1
  • Thanks for the help. I found out that I had done a major error in the db.execute function. I used hash instead of encrypt – Amol Venkataraman May 22 '18 at 15:02

You must log in to answer this question.

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