Guest User

Untitled

a guest
Sep 1st, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.99 KB | None | 0 0
  1. import os
  2. import base64
  3. import getpass
  4. import struct
  5. import time
  6. import sqlite3
  7.  
  8. class variables:
  9.     save_file   = "data\\data.db"
  10.     val_time    = 10
  11.     connection  = None
  12.     cursor      = None
  13.     DBstructure = {}
  14.     pwList      = [b'\xff', b'\xfen', b'\x00o', b'\x00_', b'\x00l', b'\x00o', b'\x00l', b'\x00']
  15.  
  16. def encodeFile(file):
  17.     buffer = b""
  18.     fopen = open(file, "rb")
  19.     buffer = fopen.read()
  20.     fopen.close()
  21.     fopen = open(file, "wb")
  22.     fopen.write(base64.b64encode(buffer))
  23.     fopen.close()
  24.  
  25. def decodeFile(file):
  26.     buffer = ""
  27.     fopen = open(file, "r")
  28.     buffer = fopen.read()
  29.     fopen.close()
  30.     fopen = open(file, "wb")
  31.     fopen.write(base64.b64decode(buffer))
  32.     fopen.close()
  33.    
  34.  
  35. def firstRUN():
  36.     if os.path.isfile(variables.save_file):
  37.         return False
  38.     else:
  39.         return True
  40.  
  41. def createTable(tableName, userName, userPassword):
  42.     decodeFile(variables.save_file)
  43.     variables.connection = sqlite3.connect(variables.save_file)
  44.     variables.cursor     = variables.connection.cursor()
  45.     cmd = "CREATE TABLE "+tableName+" (name TEXT, password BLOB);"
  46.     variables.cursor.execute(cmd)
  47.     cmd = "INSERT INTO "+tableName+" VALUES('"+str(userName)+"', ?)"
  48.     variables.cursor.execute(cmd, (userPassword.encode("utf-16"),))
  49.     variables.connection.commit()
  50.     variables.connection.close()
  51.     encodeFile(variables.save_file)
  52.  
  53. def createDB():
  54.     variables.connection = sqlite3.connect(variables.save_file)
  55.     variables.connection.close()
  56.     encodeFile(variables.save_file)
  57.  
  58.     #variables.cursor = variables.connection.cursor()
  59.     #cmd = "CREATE TABLE youtube (name TEXT, password BLOB);"
  60.     #connection.commit()
  61.  
  62. def enter_create(TableName):
  63.     print("Creating password for "+TableName+".")
  64.     username = str(input("Please enter an username: "))
  65.     password = getpass.getpass("Please enter an password: ")
  66.     createTable(TableName, username, password)
  67.     print("Done.")
  68.     time.sleep(5)
  69.  
  70. def getTableVals(tableName):
  71.     decodeFile(variables.save_file)
  72.     variables.connection = sqlite3.connect(variables.save_file)
  73.     variables.cursor     = variables.connection.cursor()
  74.     cmd = "SELECT * FROM "+tableName
  75.     variables.cursor.execute(cmd)
  76.     results = variables.cursor.fetchall()
  77.     variables.connection.close()
  78.     encodeFile(variables.save_file)
  79.     name = results[0][0]
  80.     password = results[0][1].decode('utf16')
  81.     print("Username: "+name)
  82.     print("Password: "+password)
  83.     time.sleep(10)
  84.  
  85. def enter_receive(TableName):
  86.     try:
  87.         getTableVals(TableName)
  88.     except Exception as e:
  89.         #print(str(e))
  90.         print("No entry named "+TableName+".")
  91.         time.sleep(5)
  92.  
  93. def validate_user():
  94.     print("\n"*100)
  95.     if firstRUN():
  96.         createDB()
  97.     else:
  98.         pass
  99.     print("Logged in!")
  100.     time.sleep(5)
  101.     while True:
  102.         print("\n"*100)
  103.         print("Enter 'create [e.g. YouTube]' to create a new password.")
  104.         print("Enter 'receive [e.g. YouTube]' to receive your data.")
  105.         print("\n")
  106.         command = str(input("$ "))
  107.         if len(command.split(" ")) == 2:
  108.             if command.split(" ")[0].lower() == "create":
  109.                 print("\n"*100)
  110.                 enter_create(command.split(" ")[1])
  111.             elif command.split(" ")[0].lower() == "receive":
  112.                 print("\n"*100)
  113.                 enter_receive(command.split(" ")[1])
  114.             else:
  115.                 print("'"+command+"' is not valid.")
  116.                 time.sleep(5)
  117.         else:
  118.             print("'"+command+"' is not valid.")
  119.             time.sleep(5)
  120.    
  121.  
  122. def main():
  123.     while True:
  124.         if b"".join(c for c in variables.pwList).decode("utf-16") == getpass.getpass():
  125.             validate_user()
  126.         else:
  127.             print("Wrong password. Please wait %d seconds and try again..." % variables.val_time)
  128.             time.sleep(variables.val_time)
  129.             variables.val_time *= 2
  130.  
  131. if __name__ == "__main__":
  132.     main()
Add Comment
Please, Sign In to add comment