Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. @app.route('/login', methods=['GET','POST'])
  2. def login():
  3.     if request.method == 'POST':
  4.         email = request.form['email']
  5.         password = request.form['password'].encode('utf-8')
  6.  
  7.         cur = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
  8.         cur.execute("SELECT * FROM users WHERE user_email=%s",(email))
  9.         user = cur.fetchone()
  10.         cur.close()
  11.  
  12.         if len(user) > 0:
  13.             if bcrypt.hashpw(password, user['password'].encode('utf-8')) == user['password'].encode('utf-8'):
  14.                 session['name'] == user['name']
  15.                 session['email'] == user['email']
  16.                 return render_template("home.html")
  17.         else:
  18.             return "Username or Password Incorrect."
  19.     else:
  20.         return render_template('login.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement