MySQL and Python

Thread Solved
Reply

Join Date: Nov 2008
Posts: 58
Reputation: adam291086 is an unknown quantity at this point 
Solved Threads: 0
adam291086 adam291086 is offline Offline
Junior Poster in Training

MySQL and Python

 
0
  #1
Nov 20th, 2008
I am trying to create an authentication script. I am trying to use the PASSWORD function within Mysql but it wont work. Any ideas

  1. #!/usr/bin/python
  2. # e begoli, python connector for mysql
  3. # import MySQL module
  4. import MySQLdb
  5. import cgi
  6. print "Content-type: text/html\n"
  7.  
  8. # connection
  9. db = MySQLdb.connect(host = "localhost", user = "dsfdsfds1", passwd = "dsfdsfdsfsdM5HQ", db = "dsfdsfdsfdsfdsf")
  10.  
  11. form = cgi.FieldStorage()
  12. if form.has_key("username")and form["username"].value !="" and form.has_key("password") and form["password"].value !="":
  13. username = form["username"].value
  14. password = form["password"].value
  15.  
  16. # create a database cursor
  17. cursor = db.cursor()
  18.  
  19. # execute SQL select statement
  20. cursor.execute("SELECT * FROM User WHERE UserName = username AND Password = PASSWORD(password)")
  21.  
  22. # get the number of rows in the resultset
  23. numrows = int(cursor.rowcount)
  24.  
  25. if numrows ==1:
  26. print "your in"
  27. else:
  28. 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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 58
Reputation: adam291086 is an unknown quantity at this point 
Solved Threads: 0
adam291086 adam291086 is offline Offline
Junior Poster in Training

Re: MySQL and Python

 
0
  #2
Nov 20th, 2008
solved it by doing

  1. cursor.execute("SELECT * FROM User WHERE UserName = username AND Password = PASSWORD('"+password+"')")
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC