Skip to content

Instantly share code, notes, and snippets.

@ks888
Created May 16, 2016 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ks888/e0a50e1c87b8b4c276844be39ab3dbc5 to your computer and use it in GitHub Desktop.
Save ks888/e0a50e1c87b8b4c276844be39ab3dbc5 to your computer and use it in GitHub Desktop.
from bottle import route, run, request, default_app, HTTPResponse
import mysql.connector
@route('/login')
def login():
username = request.query.id
password = request.query.password
connect = mysql.connector.connect(db="test", host="localhost", port=3306, user="root")
cur = connect.cursor()
sql = "select id from user where id='%s' and pass='%s'" % (username, password)
cur.execute(sql)
rows = cur.fetchall()
if len(rows) != 0:
body = '\n'.join([user for (user,) in rows])
resp = HTTPResponse(status=200, body=body)
else:
resp = HTTPResponse(status=401)
cur.close()
connect.close()
return resp
@route('/')
def healthcheck():
return ""
app = default_app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment