-
Notifications
You must be signed in to change notification settings - Fork 0
/
plaintext.py
32 lines (25 loc) · 1 KB
/
plaintext.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
from .error import UsernameTaken, BadLogin, PasswordTooShort, PasswordTooLong
class PlainText:
code = "plaintext"
name = "Plain Text"
schema = '''
CREATE TABLE IF NOT EXISTS plaintext (
username VARCHAR(16) PRIMARY KEY,
password VARCHAR(16)
)
'''
def login(self, cursor, username, password):
cursor.execute("SELECT count(*) FROM plaintext WHERE username=%s AND password=%s", (username, password))
result = cursor.fetchone()
if result[0] == 0:
raise BadLogin()
def create_account(self, cursor, username, password):
if len(password) < 8:
raise PasswordTooShort()
if len(password) > 16:
raise PasswordTooLong()
cursor.execute("SELECT count(*) FROM plaintext WHERE username=%s", (username,))
result = cursor.fetchone()
if result[0] > 0:
raise UsernameTaken()
cursor.execute("INSERT INTO plaintext (username, password) VALUES (%s, %s)", (username, password))