This is a registration and login script I have made in Python 3. It uses a MySQL database. In the future I might use it with my Blackjack game and add a row called
money, but for now I would like to hear your opinion about this script since I have little to no experience in SQL.
import cymysql from getpass import getpass def get_user_info(): while True: email = input("Input your Email address (max. 64 chars.): ") password = getpass("Input a password (max. 64 chars.): ") if len(email) < 64 and len(password) < 64: return email, password def register(cur, email, password): cur.execute("INSERT INTO `users` (`Email`, `Password`) VALUES (%s, %s)", (email, password)) print("You've succesfully registered!") def login(cur, email, password): cur.execute("SELECT * FROM `users` WHERE `Email`=%s AND `Password`=%s LIMIT 1", (email, password)) rows = cur.fetchall() if rows: print("You've succesfully logged-in!") else: print("You failed logging-in!") def check_account(cur, email): cur.execute("SELECT * FROM `users` WHERE `Email`=%s LIMIT 1", (email,)) row = cur.fetchone() return row def main(): conn = cymysql.connect( host='127.0.0.1', user='root', passwd='', db='david' ) cur = conn.cursor() email = '' password = '' email, password = get_user_info() check = check_account(cur, email) if check: login(cur, email, password) else: register(cur, email, password) cur.close() conn.close() if __name__ == '__main__': main()