Skip to content

Instantly share code, notes, and snippets.

@KarimullinArthur
Last active March 30, 2023 11:40
Show Gist options
  • Save KarimullinArthur/75bbd88ba802fcd021b6e1757481dce4 to your computer and use it in GitHub Desktop.
Save KarimullinArthur/75bbd88ba802fcd021b6e1757481dce4 to your computer and use it in GitHub Desktop.
Ригистрация, учусь работать с БД
import sqlite3
conn = sqlite3.connect('date.db')
cur = conn.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
password TEXT);""")
conn.commit()
def rigistration():
global conn
global cur
login = input("Input your login\n> ")
check = cur.execute('SELECT * FROM users WHERE name=?', (login, ))
if check.fetchone() is None:
password = input("Input your password\n> ")
passwordCheck = input("Input password again\n> ")
if password == passwordCheck:
inp = (login,password)
cur.execute("INSERT INTO users(name,password) VALUES(?,?)",inp)
conn.commit()
print("All right, you are registered!")
else:
print("Oops,you entered two different passwords. Please try again.")
else:
print('Login busy')
rigistration()
@tharynot
Copy link

Password must be stored in hash (not plaintext). Hash is string that always has certain length, which is unique for each set of bits. For example passwords in (GNU/)Linux-based systems are stored in /etc/shadow in hash. For example sha1 from string a is 3f786850e387550fdab836ed7e6dc881de23001b, but sha1sum from string a (previous string with space at end) is 8094deb9fe1d7d15598a8e7b876e151810630635. I recommend to use sha512 hash function (is available in most modern Unix-like systems by default using sha512sum command from terminal)

Sorry for my English

@tharynot
Copy link

c

@KarimullinArthur
Copy link
Author

Я же написал, что просто учусь работать с бд, да это и было-то когда.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment