Advertisement
Guest User

additional

a guest
Dec 20th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. import hashlib
  2. import mysql.connector
  3. import zipfile
  4. import sql
  5.  
  6. mydb = mysql.connector.connect(host = 'localhost',
  7.                                user = 'root',
  8.                                password = 'root',
  9.                                database = 'testdb')
  10.  
  11. mycursor = mydb.cursor()
  12.  
  13. def hash():
  14.     BLOCKSIZE = 65536
  15.     hasher = hashlib.md5()
  16.     with open('hello.txt', 'rb') as afile:
  17.         buf = afile.read(BLOCKSIZE)
  18.         while len(buf) > 0:
  19.             hasher.update(buf)
  20.             buf = afile.read(BLOCKSIZE)
  21.     print(hasher.hexdigest())
  22.  
  23. def login():
  24.     print("Введите uid")
  25.     uid=int(input())
  26.     print("Введите пароль")
  27.     passwd=input()
  28.     passwd=passwd.encode('utf-8')
  29.     hash_pass=hashlib.md5(passwd).hexdigest()
  30.     print(hash_pass)
  31.     find="SELECT * FROM users WHERE uid = {uid}".format(uid=uid)
  32.     mycursor.execute(find)
  33.     account=mycursor.fetchall()[0]
  34.     find="SELECT name FROM users WHERE uid = {uid}".format(uid=uid)
  35.     mycursor.execute(find)
  36.     uid_name=mycursor.fetchall()[0][0]
  37.     if account[-2]==hash_pass:
  38.         print("Добро пожаловать")
  39.         return (True, uid, uid_name)
  40.     else:
  41.         print('Неправильный uid или пароль')
  42.         return (False, 0)
  43.  
  44.  
  45.  
  46. def archive(uid):
  47.     names = []
  48.     while True:
  49.         print("Введите id файла")
  50.         name=input()
  51.         s=sql.find_file_id(name)
  52.         names.append(s)
  53.         if name=="/close":
  54.             break
  55.     archname = r"C:\Users\mi\SAD\Server\archive\\"+'archive_'+str(uid)+'.zip'
  56.     zip_file = zipfile.ZipFile(archname, 'w')
  57.     for i in names:
  58.         zip_file.write(i)
  59.     zip_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement