Guest User

Untitled

a guest
Jan 30th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import cgi, cgitb
  4. import mysql.connector
  5. import requests
  6. import sys
  7. cgitb.enable()
  8.  
  9. def login():
  10. flag= False
  11. cnx = mysql.connector.connect(user='root', passwd='root',
  12. host='localhost',
  13. database='BLOG')
  14. form = cgi.FieldStorage()
  15. user_name = form.getvalue('user_name')
  16. password = form.getvalue('password')
  17. check_user = "select user_name,password from users where user_name = 'hussain8' and password='hussain008'"
  18. data_user = (user_name,password)
  19. cur = cnx.cursor()
  20. cur.execute(check_user)
  21. rows = cur.fetchall()
  22. if isEmpty(rows):
  23. #print (cur.fetchall())
  24. with requests.session(user_name,password) as s:
  25. payload = {
  26. 'username': user_name,
  27. 'pass': password
  28. }
  29. url='http://localhost/login.py'
  30. s.get(url)
  31. s.post(url, data=payload)
  32. print 'Location:/test1.py'
  33. print "Content-type: text/html"
  34. print
  35. else:
  36. print 'Location:/loginError.py'
  37. print "Content-type: text/html"
  38. print
  39.  
  40. def isEmpty(dictionary):
  41. for element in dictionary:
  42. if element:
  43. return True
  44. return False
  45.  
  46.  
  47. login()
  48.  
  49. and the file where i want to use:
  50.  
  51. #!/usr/bin/env python
  52. import requests
  53. import json
  54. s=requests.session()
  55. req=s.get('http://localhost/login.py')
  56. print(req.json)
  57. print("Content-Type: text/html;charset=utf-8")
  58. print""
  59. print "Content-type:text/htmlrnrn"
  60. print""
  61. print """<html>
  62. <head></head>
  63. <body>
  64. <h1>user name = %print(name)%</h1>
  65. <h1>user name = %print(password)%</h1>
  66. </body>
  67. <script src="js/jquery-1.11.3.min.js"></script>
  68. <script src="js/bootstrap.min.js"></script>
  69. </html>
  70. """
Add Comment
Please, Sign In to add comment