Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.65 KB | None | 0 0
  1. import sqlite3
  2.  
  3. def sqlConnect():
  4.     conn = sqlite3.connect("mail.db")
  5.     cursor = conn.cursor()
  6.     conn.set_trace_callback(print)
  7.     return cursor, conn
  8.  
  9. def auth():
  10.     cursor,conn = sqlConnect()
  11.    
  12.     username = input('Enter your username:')
  13.     passowrd = input('Enter your password:')
  14.  
  15.     cursor.execute("SELECT user_id FROM users WHERE username = ?", (username, ))
  16.  
  17.     userId  = cursor.fetchall()
  18.     print(userId)
  19.    
  20.     if len(userId) != 0:
  21.         authStatus = 1
  22.         print('Welcome!')
  23.     else:
  24.         choice = input('Want to create an account? (y\n):')
  25.         if choice == 'y':
  26.             register()
  27.         else:
  28.             print('Good bye!')
  29.     return userId, authStatus
  30.  
  31. def register():
  32.     cursor, conn = sqlConnect()
  33.    
  34.     username    = input('Enter your username: ')
  35.     password    = input('Enter your password: ')
  36.     name        = input('Enter your name: ')
  37.     status      = input('Enter your status (teacher, student): ')
  38.  
  39.     if username != '' and password != '':
  40.         cursor.execute("SELECT user_id FROM users WHERE username = ?", (username, ))
  41.         userId  = cursor.fetchall()
  42.         if len(userId) != 0:
  43.             print('Please choose another username')
  44.             register()
  45.         else:
  46.             query = '''
  47.             INSERT INTO users
  48.                 (username, password, name, status)
  49.             VALUES
  50.                  (?,?,?,?)
  51.                '''
  52.             data = (username, password, name, status)
  53.             cursor.execute(query, data)
  54.             conn.commit()
  55.             print('Nice to meet you,', name,'! You have been successfuly registered with the following details:', username,':',password, '. You can now sign in.')
  56.             auth()
  57.     else:
  58.         print('Neither username nor password can be empty!')
  59.         register()
  60.  
  61. def readMail():
  62.     pass
  63.  
  64. def main():
  65.     print('Console Messenger v0.1')
  66. ##    print('--------------------------------------')
  67. ##    print('|Ivan Ivanov                         |')
  68. ##    print('|------------------------------------|')
  69. ##    print('|Topic Theme                         |')
  70. ##    print('|                                    |')
  71. ##    print('|------------------------------------|')
  72. ##    print('|Letter data                         |')
  73. ##    print('|                                    |')
  74. ##    print('|                                    |')
  75. ##    print('--------------------------------------')
  76.    
  77.     action = input('Would you like to sign in or sign up?: ')
  78.     if action == 'login':
  79.         auth()
  80.     if action == 'register':
  81.         register()
  82.  
  83. if __name__ == "__main__":
  84.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement