-
Notifications
You must be signed in to change notification settings - Fork 0
/
touch.py
65 lines (61 loc) · 2.04 KB
/
touch.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import time as T
import sqlite3
import hashlib
from random import choice
from string import ascii_letters
import os
from Crypto.Cipher import AES
#from browserFunctions import *
def register(un,pw,db):
db.cur.execute('SELECT * FROM auth WHERE username="{0}"'.format(un))
if db.cur.fetchone():
print('fail:userexists')
return False
userID = ''
while userID == '':
userID=''.join(choice(ascii_letters) for i in range(16))
db.cur.execute('SELECT * FROM auth WHERE id="{0}"'.format(userID))
if db.cur.fetchone():
userID = ''
allC = str(ascii_letters)
allC += '0123456789'
salt = ''.join(choice(allC) for i in range(16))
m = hashlib.sha256()
m.update(bytes(pw, 'utf-8'))
m.update(bytes(salt, 'utf-8'))
salted = m.hexdigest()
db.cur.execute('INSERT INTO auth VALUES ("{0}","{1}","{2}","{3}")'.format(un,salt,salted,userID))
db.conn.commit()
print('user created')
return True
def registerPlatform(username, password, platform,salt,ID):
conn = sqlite3.connect(r'data.db')
cur = conn.cursor()
while len(password)%16 != 0:
password += ' '
obj = AES.new(bytes(salt,'utf-8'), AES.MODE_ECB)
ciph = obj.encrypt(bytes(password,'utf-8'))
ciph = ciph.hex()
cur.execute('INSERT INTO platformLogins VALUES ("{0}","{1}","{2}","{3}")'.format(username, ciph, platform,ID))
conn.commit()
conn.close()
print('user created')
return True
def checkUser(username, password):
conn = sqlite3.connect(r'data.db')
cur = conn.cursor()
cur.execute('SELECT salt FROM auth WHERE (username="{0}");'.format(username))
val = cur.fetchone()
if not val:
print('not found')
return False
val = list(val)[0]
m = hashlib.sha256()
m.update(bytes(password, 'utf-8'))
m.update(bytes(val, 'utf-8'))
salted = m.hexdigest()
cur.execute('SELECT id FROM auth WHERE (username="{0}" and saltedhash="{1}");'.format(username, salted))
done = cur.fetchone()
if done:
return done
return False