DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   MySQL and Python (http://www.daniweb.com/forums/thread158557.html)

adam291086 Nov 20th, 2008 9:57 am
MySQL and Python
 
I am trying to create an authentication script. I am trying to use the PASSWORD function within Mysql but it wont work. Any ideas

#!/usr/bin/python
# e begoli, python connector for mysql
# import MySQL module
import MySQLdb
import cgi
print "Content-type: text/html\n"

# connection
db = MySQLdb.connect(host = "localhost", user = "dsfdsfds1", passwd = "dsfdsfdsfsdM5HQ", db = "dsfdsfdsfdsfdsf")

form = cgi.FieldStorage()
if form.has_key("username")and form["username"].value !="" and form.has_key("password") and form["password"].value !="":
    username = form["username"].value
    password = form["password"].value
   
    # create a database cursor
    cursor = db.cursor()

    # execute SQL select statement
    cursor.execute("SELECT * FROM User WHERE UserName = username AND Password = PASSWORD(password)")

    # get the number of rows in the resultset
    numrows = int(cursor.rowcount)
 
    if numrows ==1:
        print "your in"
    else:
        print "you are not authorised to view this page"
if i put PASSWORD('password') it just get the encryption for password and not the variable

adam291086 Nov 20th, 2008 10:21 am
Re: MySQL and Python
 
solved it by doing

  cursor.execute("SELECT * FROM User WHERE UserName = username AND Password = PASSWORD('"+password+"')")


All times are GMT -4. The time now is 12:29 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC