def login(): print('\n' + "Welcome back!!") global username username = input_username() mycursor.execute("select username from login where username='******'lwosch') + "'") pot = mycursor.fetchone() if pot is not None: query = "select Password_key from login where username=%r" % encrypt( username, 'lwosch') mycursor.execute(query) global key key = mycursor.fetchone()[0] print("VALID USERNAME!!!" + '\n') sum1 = 0 while sum1 < 3: pswd = input_password() mycursor.execute("select password from login where password='******'lwosch') + "' and Username='******'lwosch') + "'") a = mycursor.fetchone() if a is not None: print('\n' + '~' * 48 + '\n' + '~' * 16 + "LOGIN SUCCESSFUL" + '~' * 15 + '\n' + '~' * 48) afterloginmenu() else: print('\n' + "Incorrect password, login failed!!" + '\n' + "Try Again" + '\n') sum1 += 1 print("Three attempts to login failed. Generating OTP...") sendOTP() else: print("User does not exist\n")
def del_account(): print("This change is permanent and cannot be reverted") print( "Are you sure you would like to proceed and delete your account? \n\t 1. YES \t 2. NO" ) i = input_yesorno() if i == 1: cur = mydb.cursor() uname = input_username() print("Please re-enter your password to confirm the action") pswd = input_password() #Password being taken as input, Master table mycursor.execute("select password from login where password='******'lwosch') + "' and Username='******'lwosch') + "'") a = mycursor.fetchone() if a is not None: print("Authorization complete. Deletion in process...") query1 = "Drop table {}".format(key) cur.execute(query1) query2 = "delete from login where username='******'lwosch') + "'" cur.execute(query2) mydb.commit() cur.close() print("Account deleted successfully\n") menu() else: print("Data not found") print('\n' + '~' * 98) afterloginmenu() elif i == 2: print("Account deletion cancelled by user. No changes were made.") print('\n' + '~' * 98) afterloginmenu()
def delete_pswd(): cur = mydb.cursor() site, uname = search_procedure(key) query = "select password from {} where Username='******' and Website='{}'".format( key, encrypt(uname, key), encrypt(site, key)) cur.execute(query) data = cur.fetchone() if data is not None: print( "Do you really want to delete the password? \n\t 1. YES \t 2. NO") n = input_yesorno() if n == 1: query = "delete from {} where (Website='{}' or Website_Alias='{}') and username='******'".format( key, encrypt(site, key), encrypt(site, key), encrypt(uname, key)) cur.execute(query) mydb.commit() print("Password successfully deleted") elif n == 2: print("Password deletion denied by user") else: print("Data not found") cur.close() print('\n' + '~' * 98) afterloginmenu()
def signup( ): #this function adds the login details to the master 'login' table and creates a table for the user using the key print( '\n' + """Create an account for a secure way to store your passwords all at one place never again needing to remember them. This is the safest way to store passwords and accessing them at one go""" + '\n') global username username = input_username() while not username_duplicate(username): print("Username already used, try again!!") username = input_username() pswd = input_newpassword() key = generate_key() while not key_duplicate(key): key = generate_key( ) #FUN FACT: If all possible keys which our function can generate have been used, then this will lead to an infinite loop...OOPSSS... key_main = 'lwosch' #Use this key to encrypt anything out of the user table, lwosch is our initials encrypted using affine cipher. global email email = input_email() mycursor.execute("insert into login values('" + encrypt(username, key_main) + "','" + encrypt(pswd, key_main) + "','" + key + "','" + encrypt(email, key_main) + "')") mydb.commit() query = "create table if not exists {} (Website varchar(100) not null, Website_Alias varchar(100), Username varchar(100) not null,Password varchar(150) not null)".format( key) cur = mydb.cursor() cur.execute(query) cur.close print("User created successfully\n") menu() #now prompt the user to login
def sendOTP(): x = generateOTP() str1 = "select email from login where Username=%r" % encrypt( username, 'lwosch') mycursor.execute(str1) y = mycursor.fetchone() print("OTP sent to mail ", decrypt(y[0], 'lwosch')) server = smtplib.SMTP_SSL("smtp.gmail.com", 465) server.login("*****@*****.**", "ssllxekmtvfvtshb") message = """Greetings! We have received a request for password reset for your password manager account. The OTP required for verification is: {}. This OTP is valid only for the next 10 mins. It is advised not to disclose this to anyone. If no such request is raised, kindly ignore the message.""".format(x) server.sendmail("*****@*****.**", decrypt(y[0], 'lwosch'), message) server.quit() c, n = 0, 3 start_time = time.time() while n > 0 and c == 0: #3 attempts at entering right OTP if time.time() - start_time <= 600: OTP_received = input_otp() if x == str(OTP_received): print( "Authorization complete. Proceeding to password reset..." + '\n') pswd = input_newpassword() query = "update login set password=%r where username=%r" % ( encrypt(pswd, 'lwosch'), encrypt(username, 'lwosch')) mycursor.execute(query) mydb.commit() print( "Password successfully changed, You can now login with your new password." ) menu() else: print("Incorrect OTP!!! Try Again" + '\n') n -= 1 else: print("Timeout!!! OTP Expired" + '\n') break print( "OTP VERIFICATION FAILED. Would you like to resend OTP? \n\t 1. YES \t 2. NO" ) p = input_yesorno() if p == 1: sendOTP() else: print("Attempt to login failed." + '\n') menu()
def password_duplicate(uname, website): uname, website = encrypt(uname, key), encrypt(website, key) cur = mydb.cursor() query = "select username, website, website_alias from {}".format(key) mycursor.execute(query) data = cur.fetchall() a = set() for row in data: a.add((row[0], row[1])) n = len(a) a.add((uname, website)) m = len(a) if m == n: return False else: return True
def encrypt(self): try: input = self.inputTextVar.get() key = self.keyTextVar.get() yourAlphabet = self.yourAphabetVar.get() yourKey = self.yourKeyVar.get() print(yourAlphabet, yourKey) if key is not '': self.yourKeyVar.set('') self.yourAphabetVar.set('') self.resultTextVar.set(encrypt(input, key)) else: self.resultTextVar.set(encrypt(input, yourKey, yourAlphabet)) except Exception as ex: print(ex) self.report_callback_exception(ex)
def account_emailchange(): print("Please enter your current password to authorize the action.") pswd = input_password() #Password being taken as input, Master table mycursor.execute("select password from login where password='******'lwosch') + "' and Username='******'lwosch') + "'") a = mycursor.fetchone() if a is not None: print("Authorization complete. Initializing E-mail change...") email = input_email() query = "update login set email=%r where username=%r" % (encrypt( email, 'lwosch'), encrypt(username, 'lwosch')) mycursor.execute(query) mydb.commit() print("E-mail successfully changed.") print('\n' + '~' * 98) afterloginmenu() else: print("Authorization failed!!") print('\n' + '~' * 98) afterloginmenu()
def show_pswd(): cur = mydb.cursor() site, uname = search_procedure(key) if site is not None and uname is not None: query = "select password from {} where Username='******' and Website='{}'".format( key, encrypt(uname, key), encrypt(site, key)) cur.execute(query) data = cur.fetchone() else: afterloginmenu() if data is not None: print( '\nThe requested password will be displayed in a new window and will only remain visible for 30 seconds for security reasons.' ) ciphertext = data[0] x = decrypt(ciphertext, key) show_password(x) else: print("Data not Found") print('\n' + '~' * 98) afterloginmenu()
def add_pswd(): cur = mydb.cursor() site = input_website() uname = input_username() print( "Would you like a keep an alias name for the website? \n\t 1. YES \t 2. NO" ) n = input_yesorno() alias = "" if n == 1: alias = input_alias() else: print("Website alias denied by user") while not password_duplicate(uname, site): print( "Password already stored! Use show option to view saved password.") site = input_website() uname = input_username() if n == 1: alias = input_alias() print("Would you like a suggested password? \n\t 1. YES \t 2. NO") n = input_yesorno() pswd = "" if n == 1: x = input_passwordlength() pswd = randomPassword(x - 4) print( "Random Password Generated Successfully: ", pswd ) #here x-4 is used because in the code a password of length 4 is already fixed elif n == 2: print("Random password generation denied by user") pswd = input_newpassword() query = "insert into {} values('{}','{}','{}','{}')".format( key, encrypt(site, key), encrypt(alias, key), encrypt(uname, key), encrypt(pswd, key)) cur.execute(query) mydb.commit() print('\n' + '~' * 98) afterloginmenu()
def username_duplicate(x): x = encrypt(x, "lwosch") cur = mydb.cursor() query = "Select username from login" mycursor.execute(query) data = cur.fetchall() a = set() for row in data: a.update(row) n = len(a) a.add(x) m = len(a) if m == n: return False else: return True
def update_pswd(): cur = mydb.cursor() site, uname = search_procedure(key) query = "select password from {} where Username='******' and Website='{}'".format( key, encrypt(uname, key), encrypt(site, key)) cur.execute(query) data = cur.fetchone() if data is not None: print("Would you like a suggested password? \n\t 1. YES \t 2. NO") n = input_yesorno() if n == 1: x = input_passwordlength() pswd = randomPassword(x - 4) print( "Random Password Generated Successfully: ", pswd ) #here x-4 is used because in the code a password of length 4 is already fixed elif n == 2: print("Random password generation denied by user") print("Enter new password below") pswd = input_newpassword() query = "update {} set password='******' where Username='******' and (Website='{}' or Website_Alias='{}')".format( key, encrypt(pswd, key), encrypt(uname, key), encrypt(site, key), encrypt(site, key)) cur.execute(query) mydb.commit() print("Password successfully updated") print( "Would you like to copy password to clipboard? \n\t 1. YES \t 2. NO" ) y = input_yesorno() if y == 1: print("Copying to clipboard...") copy(pswd) print("Password successfully copied to clipboard") else: print("Copy to clipboard denied by user") else: print("Data not found") print('\n' + '~' * 98) afterloginmenu()
def export_to_mail(usernamearea, keyarea): f = open("exporttomail.txt", "w") str2 = "select * from {}".format(keyarea) mycursor.execute(str2) data = mycursor.fetchall() L = [ "Website ", "Alias ", "User ", "Password " ] f.writelines(L) f.write("\n") for row in data: for attr in row: f.write(decrypt(attr, keyarea) + "\t" + "\t") f.write("\n") f.close() str1 = "select email from login where Username=%r" % encrypt( usernamearea, 'lwosch') mycursor.execute(str1) y = mycursor.fetchone() fromaddr = "*****@*****.**" toaddr = decrypt(y[0], 'lwosch') # instance of MIMEMultipart msg = MIMEMultipart() # storing the senders email address msg['From'] = fromaddr # storing the receivers email address msg['To'] = toaddr # storing the subject msg['Subject'] = "Password Email Sync" # string to store the body of the mail body = "Your passwords were securely and successfully synced with your mail" # attach the body with the msg instance msg.attach(MIMEText(body, 'plain')) # open the file to be sent filename = "Website Password Table" attachment = open("exporttomail.txt", "r") # instance of MIMEBase and named as p p = MIMEBase('application', 'octet-stream') # To change the payload into encoded form p.set_payload((attachment).read()) # encode into base64 encoders.encode_base64(p) p.add_header('Content-Disposition', "attachment; filename= %s" % filename) # attach the instance 'p' to instance 'msg' msg.attach(p) # creates SMTP session s = smtplib.SMTP('smtp.gmail.com', 587) # start TLS for security s.starttls() # Authentication s.login("*****@*****.**", "ssllxekmtvfvtshb") # Converts the Multipart msg into a string text = msg.as_string() # sending the mail s.sendmail(fromaddr, toaddr, text) # terminating the session s.quit() attachment.close() os.remove("exporttomail.txt") cur.close()