Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- import re
- # Database Connection
- conn = sqlite3.connect("accounts.db")
- c = conn.cursor()
- # Create table
- c.execute("""CREATE TABLE IF NOT EXISTS accounts (
- username text,
- password text
- )""")
- def signup(username, password):
- u = 0
- p = 0
- u_req = "You must have a username with a minimum length of 8 and a maximum length of 16!"
- p_req = "Your password must have at least one letter, one number, and one character from \"$#@\"!"
- if len(username) >= 8 and len(username) <= 16:
- c.execute("SELECT * FROM accounts WHERE username=?",
- (username)
- )
- if c.fetchall() != []:
- print("Sorry, but the username \"" + username + "\" is taken!")
- else:
- u = 1
- m1 = re.search('[a-zA-Z]', password)
- hasLet = m1[0].isalpha()
- hasNum = any(char.isdigit() for char in password)
- if password.includes("$") or password.includes("#") or password.includes("@"):
- hasSpecChar = True
- if hasLet == True and hasNum == True and hasSpecChar == True:
- p = 1
- if u == 1 and p == 1:
- c.execute("INSERT INTO accounts (username, password) VALUES (?, ?)",
- (username, password)
- )
- conn.commit()
- elif u == 0 and p == 0:
- print(u_req + "\n" + p_req)
- elif u == 0:
- print(u_req)
- elif p == 0:
- print(p_req)
- def login(username, password):
- c.execute("SELECT * FROM accounts WHERE username=? AND password=?",
- (username, password)
- )
- if c.fetchall() != []:
- return username + password
- else:
- print("Invalid username or password.")
- main()
- # Main Program
- def main():
- # Prompts
- choice1 = input("Would you like to signin or signup? ")
- if choice1.lower() == "signin" or choice1.lower() == "login":
- login(input("Username: "), input("Password: "))
- elif choice1.lower() == "signup" or choice1.lower() == "register":
- signup(input("Username: "), input("Password: "))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement