Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- def sqlConnect():
- conn = sqlite3.connect("mail.db")
- cursor = conn.cursor()
- conn.set_trace_callback(print)
- return cursor, conn
- def auth():
- cursor,conn = sqlConnect()
- username = input('Enter your username:')
- passowrd = input('Enter your password:')
- cursor.execute("SELECT user_id FROM users WHERE username = ?", (username, ))
- userId = cursor.fetchall()
- print(userId)
- if len(userId) != 0:
- authStatus = 1
- print('Welcome!')
- else:
- choice = input('Want to create an account? (y\n):')
- if choice == 'y':
- register()
- else:
- print('Good bye!')
- return userId, authStatus
- def register():
- cursor, conn = sqlConnect()
- username = input('Enter your username: ')
- password = input('Enter your password: ')
- name = input('Enter your name: ')
- status = input('Enter your status (teacher, student): ')
- if username != '' and password != '':
- cursor.execute("SELECT user_id FROM users WHERE username = ?", (username, ))
- userId = cursor.fetchall()
- if len(userId) != 0:
- print('Please choose another username')
- register()
- else:
- query = '''
- INSERT INTO users
- (username, password, name, status)
- VALUES
- (?,?,?,?)
- '''
- data = (username, password, name, status)
- cursor.execute(query, data)
- conn.commit()
- print('Nice to meet you,', name,'! You have been successfuly registered with the following details:', username,':',password, '. You can now sign in.')
- auth()
- else:
- print('Neither username nor password can be empty!')
- register()
- def readMail():
- pass
- def main():
- print('Console Messenger v0.1')
- ## print('--------------------------------------')
- ## print('|Ivan Ivanov |')
- ## print('|------------------------------------|')
- ## print('|Topic Theme |')
- ## print('| |')
- ## print('|------------------------------------|')
- ## print('|Letter data |')
- ## print('| |')
- ## print('| |')
- ## print('--------------------------------------')
- action = input('Would you like to sign in or sign up?: ')
- if action == 'login':
- auth()
- if action == 'register':
- register()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement