· 5 years ago · Jun 28, 2020, 01:42 PM
1import sqlite3
2from hashlib import sha256
3
4
5def user_data():
6 login = input("Input login: ")
7 password = sha256(input("Input password: ").encode()).hexdigest()
8 input_task = input("You want registration or authorization?: ")
9
10 conn = sqlite3.connect("mydatabase.db")
11 cursor = conn.cursor()
12
13 cursor.execute(
14 """
15 CREATE TABLE
16 IF NOT EXISTS user
17 (
18 id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
19 login,
20 password
21 )
22 """
23 )
24
25 cursor.execute(
26 """
27 CREATE TABLE
28 IF NOT EXISTS notes
29 (
30 user_Id Integer not null,
31 note_title,
32 note_text,
33 FOREIGN KEY (user_id) REFERENCES information (id)
34 )
35 """
36 )
37
38 check_user = cursor.execute(
39 """
40 SELECT id, login, password
41 FROM user
42 WHERE login = ?""", (login,)
43 ).fetchone()
44 print(check_user)
45
46 conn.commit()
47 conn.close()
48
49
50def registration(login, password, check_user = ''):
51 if check_user is None:
52 cursor.execute(
53 """
54 INSERT INTO user (login, password)
55 VALUES (?, ?)""", (login, password)
56 )
57 else:
58 print("Thy another user!")
59
60def authorization():
61 if check_user is not None:
62 if password == check_user[2]:
63 print(f"Welcome, {login}")
64
65 while True:
66 user_choice = input("Do you want to create a note or sign out:")
67 if user_choice == "create a note":
68 note_title = input("Enter the names for the task: ")
69 note_text = input("Enter text of the task: ")
70 cursor.execute(
71 """
72 INSERT INTO notes (user_id, note_title,note_text)
73 VALUES(?, ?, ?)
74 """, (check_user[0], note_title, note_text))
75 continue
76 else:
77 break
78
79 else:
80 print("Please login or password incorrect, try again!!")