-
Notifications
You must be signed in to change notification settings - Fork 2
/
python_database.py
44 lines (36 loc) · 1.2 KB
/
python_database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sqlite3
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS users (
first_name TEXT,
last_name TEXT,
email TEXT UNIQUE,
password TEXT
)
""")
conn.commit()
def register_user():
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
while True:
email = input("Enter your email: ")
password1 = input("Enter your password: ")
password2 = input("Confirm your password: ")
# Check password correctness
if password1 == password2:
try:
cursor.execute("""
INSERT INTO users (first_name, last_name, email, password)
VALUES (?, ?, ?, ?)
""", (first_name, last_name, email, password2))
conn.commit()
print("You have successfully created an account.")
break
except sqlite3.IntegrityError:
print("Error: This email is already registered.")
else:
print("Your passwords must match.")
register_user()
cursor.close()
conn.close()