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

solved it by doing

cursor.execute("SELECT * FROM User WHERE UserName = username AND Password = PASSWORD('"+password+"')")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.