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 decrypt(self): try: encrypted_text = self.resultTextVar.get() key = self.keyTextVar.get() yourAlphabet = self.yourAphabetVar.get() yourKey = self.yourKeyVar.get() if key is not '': self.yourKeyVar.set('') self.yourAphabetVar.set('') self.inputTextVar.set(decrypt(encrypted_text, key)) else: self.inputTextVar.set( decrypt(encrypted_text, yourKey, yourAlphabet)) except Exception as ex: print(ex) self.report_callback_exception(ex)
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 search_procedure(key): print( "Please choose an method to search:\n\t1. Show all websites\n\t2. Search a website\n\t3. Exit" ) n = input_searchmenu() cur = mydb.cursor() if n == 1: cur.execute( "select website,website_alias,username from {}".format(key)) data = cur.fetchall() ctr = 0 print('_' * 98) print(f"|| S.No | {'Website':34} | {'Alias':30} | {'Username':15} ||") print('-' * 98) for i in data: ctr += 1 site = decrypt(i[0], key) alias = decrypt(i[1], key) uname = decrypt(i[2], key) print(f"|| {ctr:02} | {site:34} | {alias:30} | {uname:15} ||") print('_' * 98 + '\n') sno = input_sno(ctr) site = decrypt(data[sno - 1][0], key) uname = decrypt(data[sno - 1][2], key) return (site, uname) elif n == 2: print("Enter website or alias to be searched") search_string = input_alias() cur.execute( "select website,website_alias,username from {}".format(key)) data = cur.fetchall() cur.close() L = [] for i in data: #decrypting site = decrypt(i[0], key) alias = decrypt(i[1], key) uname = decrypt(i[2], key) L += [ (site, alias, uname), ] M = [] for i in range(len(L)): L[i] += ((len( ((L[i][0] + L[i][1]).lower()).split(search_string.lower())) - 1) * len(search_string), ) L.sort(key=lambda x: x[-1], reverse=True) for i in range(len(L)): if L[i][-1] > 0: M += [tuple(x for x in L[i] if type(x) == str)] if len(M) > 10: M = M[:10] for i in range(len(M)): M[i] = (i + 1, ) + M[i] ctr = 0 print('_' * 98) print(f"|| S.No | {'Website':34} | {'Alias':30} | {'Username':15} ||") print('-' * 98) for i in M: #Write code so that if M is empty, then an error message is diplayed and user is asked to search again. ctr += 1 site = i[1] alias = i[2] uname = i[3] print(f"|| {ctr:02} | {site:34} | {alias:30} | {uname:15} ||") print('_' * 98 + '\n') sno = input_sno(ctr) site = M[sno - 1][1] uname = M[sno - 1][3] return (site, uname) elif n == 3: print( 'This functionality will be available soon.... ;)' ) #Tejas was recieving some errors while trying to do this, pls look into the matter search_procedure(key)
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()