Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import base64
- import getpass
- import struct
- import time
- import sqlite3
- class variables:
- save_file = "data\\data.db"
- val_time = 10
- connection = None
- cursor = None
- DBstructure = {}
- pwList = [b'\xff', b'\xfen', b'\x00o', b'\x00_', b'\x00l', b'\x00o', b'\x00l', b'\x00']
- def encodeFile(file):
- buffer = b""
- fopen = open(file, "rb")
- buffer = fopen.read()
- fopen.close()
- fopen = open(file, "wb")
- fopen.write(base64.b64encode(buffer))
- fopen.close()
- def decodeFile(file):
- buffer = ""
- fopen = open(file, "r")
- buffer = fopen.read()
- fopen.close()
- fopen = open(file, "wb")
- fopen.write(base64.b64decode(buffer))
- fopen.close()
- def firstRUN():
- if os.path.isfile(variables.save_file):
- return False
- else:
- return True
- def createTable(tableName, userName, userPassword):
- decodeFile(variables.save_file)
- variables.connection = sqlite3.connect(variables.save_file)
- variables.cursor = variables.connection.cursor()
- cmd = "CREATE TABLE "+tableName+" (name TEXT, password BLOB);"
- variables.cursor.execute(cmd)
- cmd = "INSERT INTO "+tableName+" VALUES('"+str(userName)+"', ?)"
- variables.cursor.execute(cmd, (userPassword.encode("utf-16"),))
- variables.connection.commit()
- variables.connection.close()
- encodeFile(variables.save_file)
- def createDB():
- variables.connection = sqlite3.connect(variables.save_file)
- variables.connection.close()
- encodeFile(variables.save_file)
- #variables.cursor = variables.connection.cursor()
- #cmd = "CREATE TABLE youtube (name TEXT, password BLOB);"
- #connection.commit()
- def enter_create(TableName):
- print("Creating password for "+TableName+".")
- username = str(input("Please enter an username: "))
- password = getpass.getpass("Please enter an password: ")
- createTable(TableName, username, password)
- print("Done.")
- time.sleep(5)
- def getTableVals(tableName):
- decodeFile(variables.save_file)
- variables.connection = sqlite3.connect(variables.save_file)
- variables.cursor = variables.connection.cursor()
- cmd = "SELECT * FROM "+tableName
- variables.cursor.execute(cmd)
- results = variables.cursor.fetchall()
- variables.connection.close()
- encodeFile(variables.save_file)
- name = results[0][0]
- password = results[0][1].decode('utf16')
- print("Username: "+name)
- print("Password: "+password)
- time.sleep(10)
- def enter_receive(TableName):
- try:
- getTableVals(TableName)
- except Exception as e:
- #print(str(e))
- print("No entry named "+TableName+".")
- time.sleep(5)
- def validate_user():
- print("\n"*100)
- if firstRUN():
- createDB()
- else:
- pass
- print("Logged in!")
- time.sleep(5)
- while True:
- print("\n"*100)
- print("Enter 'create [e.g. YouTube]' to create a new password.")
- print("Enter 'receive [e.g. YouTube]' to receive your data.")
- print("\n")
- command = str(input("$ "))
- if len(command.split(" ")) == 2:
- if command.split(" ")[0].lower() == "create":
- print("\n"*100)
- enter_create(command.split(" ")[1])
- elif command.split(" ")[0].lower() == "receive":
- print("\n"*100)
- enter_receive(command.split(" ")[1])
- else:
- print("'"+command+"' is not valid.")
- time.sleep(5)
- else:
- print("'"+command+"' is not valid.")
- time.sleep(5)
- def main():
- while True:
- if b"".join(c for c in variables.pwList).decode("utf-16") == getpass.getpass():
- validate_user()
- else:
- print("Wrong password. Please wait %d seconds and try again..." % variables.val_time)
- time.sleep(variables.val_time)
- variables.val_time *= 2
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment