Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. def createuser(user,password,dbname):
  2. sql_insert = "INSERT INTO login VALUES
  3. ('{user}','{password}')".format(user=user, password=password)
  4. print sql_insert
  5. conn = sqlite3.connect(dbname)
  6. c = conn.cursor()
  7. c.execute(sql_insert)
  8. # Save (commit) the changes
  9. conn.commit()
  10.  
  11. import sqlite3
  12. DEBUG = True
  13. # sets up database
  14.  
  15.  
  16. def setup():
  17. conn = sqlite3.connect('Practice.db')
  18. c = conn.cursor()
  19. c.execute('''CREATE TABLE login
  20. (Username text, Password text )''')
  21. conn.commit()
  22.  
  23.  
  24. # main function
  25. def main(dbname, user, password, hummus):
  26. conn = sqlite3.connect('Practice.db')
  27. c = conn.cursor()
  28. if hummus == "newuser":
  29. print "Creating user {user}".format(user=user)
  30. createuser(user, password, dbname)
  31. else:
  32. print "Not running"
  33. pass
  34.  
  35.  
  36. # Create table
  37. #c.execute('''CREATE TABLE login
  38. # (Username text, Password text )''')
  39.  
  40. # Insert a row of data
  41. # c.execute("INSERT INTO username VALUES
  42. ('raw_input()','BUY','RHAT',100,35.14)")
  43.  
  44. # creats new user in table 'username'
  45.  
  46.  
  47. # creats new user in table 'username'
  48. def createuser(user,password,dbname):
  49. sql_insert = "INSERT INTO login VALUES
  50. ('{user}','{password}')".format(user=user, password=password)
  51. print sql_insert
  52. conn = sqlite3.connect(dbname)
  53. c = conn.cursor()
  54. c.execute(sql_insert)
  55. # Save (commit) the changes
  56. conn.commit()
  57.  
  58. # We can also close the connection if we are done with it.
  59. # Just be sure any changes have been committed or they will be
  60. lost.
  61. conn.close()
  62.  
  63.  
  64. if __name__ == '__main__':
  65. #setup()
  66. #exit()
  67. if DEBUG:
  68. db = 'Practice.db'
  69. user = 'tim'
  70. password = 'massimo'
  71. pass_check = True
  72. main(db, user, password, 'newuser')
  73.  
  74. else:
  75. db = 'Practice.db'
  76. user = raw_input('Enter username ')
  77. password = raw_input('Enter password ')
  78. pass_check = raw_input('verify password ')
  79. if not password == pass_check:
  80. print ('Passwords do not match. ')
  81.  
  82. main(db, user, password, 'newuser')
  83. #conn = sqlite3.connect(dbname)
  84. #conn.commit()
  85. #elif perform == ("login",'Login'):
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. #main(db, user, password, action)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement