How to use retrieve_pwd method in avocado

Best Python code snippet using avocado_python

password_generator.py

Source:password_generator.py Github

copy

Full Screen

1# Password Generator2from tkinter import *34import secrets56import pyperclip78from win10toast import ToastNotifier910import mysql.connector1112notifier = ToastNotifier()1314# DB1516mydb = mysql.connector.connect(17 host="localhost",18 user="root",19 password="root"20)2122dbcursor = mydb.cursor()2324# Create a DB if not exists25dbcursor.execute('CREATE DATABASE IF NOT EXISTS password_manager')26# set the database after creation27mydb.database = 'password_manager'28# Create a table if not exists29dbcursor.execute(30 'CREATE TABLE IF NOT EXISTS accounts (email varchar(80), password varchar(80), username varchar(80), url varchar(80) PRIMARY KEY)')3132UPPER_CASE_ALPHABETS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',33 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']3435LOWER_CASE_ALPHABETS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',36 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']3738SPECIAL_CHARACTERS = ['~', '`', '!', '@', '#', '$', '%', '^', '&', '*',39 '(', ')', '_', '-', '+', '=', '{', '[', '}', ']', '|', '\\', ':', ';', '<', ',', '>', '.', '?', '/']4041NUMERICAL_CHARACTERS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']4243select_uppercase = ''44select_special_char = ''45select_numerical_char = ''4647var_uppercase = 048var_special = 049var_numerical = 05051resultant_password = ''5253your_password = ''5455root = ''5657email_text = ''58username_text = ''59url_text = ''60password_text = ''6162txtEmail = ''63txtPassword = ''64txtUsername = ''65txtURL = ''666768def mainWindow():69 global select_uppercase, select_special_char, select_numerical_char, var_numerical, var_special, var_uppercase, resultant_password, root70 root = Tk()71 root.config(bg="white")72 root.title("PASSWORD GENERATION AND MANAGEMENT SYSTEM")73 root.geometry("700x450+0+0")74 root.resizable(False, False)75 Tops = Frame(root, width=700, height=50, bd=16, relief="raise")76 Tops.pack(side=TOP)77 mainTitle = Label(Tops, text='Password Generator', borderwidth=1, relief="groove",78 fg="steel blue", font=('arial', 15, 'bold'), bd=10, anchor='w')79 mainTitle.grid(row=0, column=0)80 LF = Frame(root, width=400, height=450, bd=16, relief="raise")81 LF.pack(side=LEFT)82 RF = Frame(root, width=300, height=450, bd=16, relief="raise")83 RF.pack(side=RIGHT)84 preferences = Label(LF, text='Select your preferences',85 fg="steel blue", font=('arial', 12, 'bold'))86 preferences.grid(row=0, column=0, padx=10, pady=10)87 var_uppercase = IntVar()88 var_special = IntVar()89 var_numerical = IntVar()90 select_uppercase = Checkbutton(LF, text="Include Uppercase Alphabets", variable=var_uppercase,91 onvalue=1, offvalue=0).grid(row=1, column=0, padx=10, pady=10)92 select_special_char = Checkbutton(LF, text="Include Special Characters", variable=var_special,93 onvalue=1, offvalue=0).grid(row=2, column=0, padx=10, pady=10)94 select_numerical_char = Checkbutton(LF, text="Include Numerical Characters",95 variable=var_numerical, onvalue=1, offvalue=0).grid(row=3, column=0, padx=10, pady=10)96 resultant_password_txt = Label(97 LF, text='Resultant Password:', fg="steel blue", font=('arial', 11, 'bold'))98 resultant_password_txt.grid(row=4, column=0, padx=10, pady=10)99 resultant_password = Label(100 LF, text='gsgdhg2hh3h&@345', fg="steel blue", font=('arial', 11, 'bold'), width=16)101 resultant_password.grid(row=4, column=1, padx=10, pady=10)102103 generate_btn = Button(RF, text="GENERATE RANDOM PASSWORD", command=generatePassword,104 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)105 generate_btn.grid(row=0, column=0, padx=5, pady=5)106 copy_btn = Button(RF, text="COPY TO CLIPBOARD", command=lambda: copyToClipboard("Password Generator Notifier", "Password Copied to Clipboard Successfully!",107 resultant_password.cget('text')),108 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)109 copy_btn.grid(row=1, column=0, padx=5, pady=5)110 reset_btn = Button(RF, text="RESET", command=resetPreferences, pady=6,111 bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)112 reset_btn.grid(row=2, column=0, padx=5, pady=5)113 password_manager = Button(RF, text="PASSWORD MANAGER", command=lambda: passwordManager(root),114 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)115 password_manager.grid(row=3, column=0, padx=5, pady=5)116117 root.mainloop()118119120def generatePassword():121 if var_uppercase.get() == 1 and var_special.get() == 1 and var_numerical.get() == 1:122 resPassword = ''123 while True:124 get_random_lowercase = secrets.choice(LOWER_CASE_ALPHABETS)125 get_random_uppercase = secrets.choice(UPPER_CASE_ALPHABETS)126 get_random_special = secrets.choice(SPECIAL_CHARACTERS)127 get_random_numerical = secrets.choice(NUMERICAL_CHARACTERS)128129 resPassword += get_random_lowercase + get_random_uppercase + \130 get_random_special + get_random_numerical131 if len(resPassword) >= 8:132 break133 resultant_password.config(text=resPassword)134 elif var_uppercase.get() == 0 and var_special.get() == 0 and var_numerical.get() == 0:135 weak_password_warning = ToastNotifier()136 weak_password_warning.show_toast("Password Generator Notifier", "Password is Insecure! Generate a stronger one by choose one or more from the checkboxes.",137 duration=10, threaded=True, icon_path='password.ico')138 elif var_uppercase.get() == 0 and var_special.get() == 0 and var_numerical.get() == 1:139 resPassword = ''140 while True:141 get_random_lowercase = secrets.choice(LOWER_CASE_ALPHABETS)142 get_random_numerical = secrets.choice(NUMERICAL_CHARACTERS)143144 resPassword += get_random_lowercase + get_random_numerical145 if len(resPassword) >= 8:146 break147 resultant_password.config(text=resPassword)148 elif var_uppercase.get() == 0 and var_special.get() == 1 and var_numerical.get() == 0:149 resPassword = ''150 while True:151 get_random_lowercase = secrets.choice(LOWER_CASE_ALPHABETS)152 get_random_special = secrets.choice(SPECIAL_CHARACTERS)153154 resPassword += get_random_lowercase + get_random_special155 if len(resPassword) >= 8:156 break157 resultant_password.config(text=resPassword)158 elif var_uppercase.get() == 0 and var_special.get() == 1 and var_numerical.get() == 1:159 resPassword = ''160 while True:161 get_random_lowercase = secrets.choice(LOWER_CASE_ALPHABETS)162 get_random_numerical = secrets.choice(NUMERICAL_CHARACTERS)163 get_random_special = secrets.choice(SPECIAL_CHARACTERS)164165 resPassword += get_random_lowercase + get_random_special + get_random_numerical166 if len(resPassword) >= 8:167 break168 resultant_password.config(text=resPassword)169 elif var_uppercase.get() == 1 and var_special.get() == 0 and var_numerical.get() == 0:170 resPassword = ''171 while True:172 get_random_lowercase = secrets.choice(LOWER_CASE_ALPHABETS)173 get_random_uppercase = secrets.choice(UPPER_CASE_ALPHABETS)174175 resPassword += get_random_lowercase + get_random_uppercase176 if len(resPassword) >= 8:177 break178 resultant_password.config(text=resPassword)179 elif var_uppercase.get() == 1 and var_special.get() == 0 and var_numerical.get() == 1:180 resPassword = ''181 while True:182 get_random_lowercase = secrets.choice(LOWER_CASE_ALPHABETS)183 get_random_uppercase = secrets.choice(UPPER_CASE_ALPHABETS)184 get_random_numerical = secrets.choice(NUMERICAL_CHARACTERS)185186 resPassword += get_random_lowercase + get_random_uppercase + get_random_numerical187 if len(resPassword) >= 8:188 break189 resultant_password.config(text=resPassword)190 elif var_uppercase.get() == 1 and var_special.get() == 1 and var_numerical.get() == 0:191 resPassword = ''192 while True:193 get_random_lowercase = secrets.choice(LOWER_CASE_ALPHABETS)194 get_random_uppercase = secrets.choice(UPPER_CASE_ALPHABETS)195 get_random_special = secrets.choice(SPECIAL_CHARACTERS)196197 resPassword += get_random_lowercase + get_random_uppercase + get_random_special198 if len(resPassword) >= 8:199 break200 resultant_password.config(text=resPassword)201202203def copyToClipboard(title, content, textToCopy):204 textCopiedNotifier = ToastNotifier()205 pyperclip.copy(textToCopy)206 textCopiedNotifier.show_toast(title, content,207 duration=10, threaded=True, icon_path='password.ico')208209210def resetPreferences():211 var_uppercase.set(0)212 var_special.set(0)213 var_numerical.set(0)214 resultant_password.config(text='gsgdhg2hh3h&@345')215216217def passwordManager(rt):218 global email_text, username_text, url_text, password_text, txtEmail, txtPassword, txtUsername, txtURL219 rt.withdraw()220 pwd_manager = Toplevel(rt)221 pwd_manager.config(bg="white")222 pwd_manager.title("PASSWORD MANAGER")223 pwd_manager.geometry("700x450+0+0")224 pwd_manager.resizable(False, False)225 email_text = StringVar()226 username_text = StringVar()227 url_text = StringVar()228 password_text = StringVar()229 Tops = Frame(pwd_manager, width=700, height=50, bd=16, relief="raise")230 Tops.pack(side=TOP)231 mainTitle = Label(Tops, text='Password Manager', borderwidth=1, relief="groove",232 fg="steel blue", font=('arial', 15, 'bold'), bd=10, anchor='w')233 mainTitle.grid(row=0, column=0)234 LF = Frame(pwd_manager, width=400, height=450, bd=16, relief="raise")235 LF.pack(side=LEFT)236 RF = Frame(pwd_manager, width=300, height=450, bd=16, relief="raise")237 RF.pack(side=RIGHT)238 details = Label(LF, text='Enter the details',239 fg="steel blue", font=('arial', 12, 'bold'))240 details.grid(row=0, column=0, padx=10, pady=10)241 email = Label(242 LF, text='Email', fg="steel blue", font=('arial', 11, 'bold'))243 email.grid(row=1, column=0)244 txtEmail = Entry(LF, font=('arial', 11, 'bold'), bd=20, width=26,245 bg="powder blue", justify='left', textvariable=email_text)246 txtEmail.grid(row=1, column=1)247 password = Label(248 LF, text='Password', fg="steel blue", font=('arial', 11, 'bold'))249 password.grid(row=2, column=0)250 txtPassword = Entry(LF, font=('arial', 11, 'bold'), bd=20, width=26,251 bg="powder blue", justify='left', textvariable=password_text, show='*')252 txtPassword.grid(row=2, column=1)253 username = Label(254 LF, text='Username', fg="steel blue", font=('arial', 11, 'bold'))255 username.grid(row=3, column=0)256 txtUsername = Entry(LF, font=('arial', 11, 'bold'), bd=20, width=26,257 bg="powder blue", justify='left', textvariable=username_text)258 txtUsername.grid(row=3, column=1)259 url = Label(260 LF, text='URL / App Name', fg="steel blue", font=('arial', 11, 'bold'))261 url.grid(row=4, column=0)262 txtURL = Entry(LF, font=('arial', 11, 'bold'), bd=20, width=26,263 bg="powder blue", justify='left', textvariable=url_text)264 txtURL.grid(row=4, column=1)265 save_btn = Button(RF, text="SAVE", command=saveData,266 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)267 save_btn.grid(row=0, column=0, padx=5, pady=5)268 reset_btn = Button(RF, text="RESET", command=resetDataFields,269 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)270 reset_btn.grid(row=1, column=0, padx=5, pady=5)271 get_password = Button(RF, text="GET PASSWORD", command=lambda: getPassword(pwd_manager),272 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)273 get_password.grid(row=2, column=0, padx=5, pady=5)274 show_passwords = Button(RF, text="SHOW ALL PASSWORDS", command=lambda: showAllPasswords(pwd_manager),275 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)276 show_passwords.grid(row=3, column=0, padx=5, pady=5)277 back_btn = Button(RF, text="BACK", command=lambda: reinstate(rt, pwd_manager),278 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)279 back_btn.grid(row=4, column=0, padx=5, pady=5)280281 pwd_manager.mainloop()282283284def saveData():285 # save data to SQL Database286 data_to_insert = 'INSERT INTO accounts (email, password, username, url) VALUES (%s, %s, %s, %s)'287 values = (txtEmail.get(), txtPassword.get(),288 txtUsername.get(), txtURL.get())289 try:290 dbcursor.execute(data_to_insert, values)291 mydb.commit()292 dataInsertedNotifier = ToastNotifier()293 dataInsertedNotifier.show_toast("Password Manager Notifier", "Data Saved Successfully!",294 duration=10, threaded=True, icon_path='password.ico')295 resetDataFields()296 except MySQLdb.IntegrityError:297 dataInsertedNotifier = ToastNotifier()298 dataInsertedNotifier.show_toast("Password Manager Notifier", "Data Save was Unsuccessful!",299 duration=10, threaded=True, icon_path='password.ico')300301302def resetDataFields():303 email_text.set("")304 password_text.set("")305 username_text.set("")306 url_text.set("")307308309def getPassword(rt):310 # retrieve a particular password according to the query311 global email_text, username_text, url_text, password_text, txtEmail, txtPassword, txtUsername, txtURL, your_password312 rt.withdraw()313 retrieve_pwd = Toplevel(rt)314 retrieve_pwd.config(bg="white")315 retrieve_pwd.title("RETRIEVE PASSWORD")316 retrieve_pwd.geometry("750x450+0+0")317 retrieve_pwd.resizable(False, False)318 url_text = StringVar()319 Tops = Frame(retrieve_pwd, width=750, height=50, bd=16, relief="raise")320 Tops.pack(side=TOP)321 mainTitle = Label(Tops, text='Retrieve Password', borderwidth=1, relief="groove",322 fg="steel blue", font=('arial', 15, 'bold'), bd=10, anchor='w')323 mainTitle.grid(row=0, column=0)324 LF = Frame(retrieve_pwd, width=400, height=450, bd=16, relief="raise")325 LF.pack(side=LEFT)326 RF = Frame(retrieve_pwd, width=350, height=450, bd=16, relief="raise")327 RF.pack(side=RIGHT)328 details = Label(LF, text='Enter the URL / App name',329 fg="steel blue", font=('arial', 11, 'bold'))330 details.grid(row=0, column=0, padx=5, pady=5)331 url = Label(332 LF, text='URL / App Name', fg="steel blue", font=('arial', 11, 'bold'))333 url.grid(row=1, column=0)334 txtURL = Entry(LF, font=('arial', 11, 'bold'), bd=20, width=26,335 bg="powder blue", justify='left', textvariable=url_text)336 txtURL.grid(row=1, column=1)337 get_password = Button(RF, text="GET", command=retrievePasswordFromDB,338 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)339 get_password.grid(row=0, column=0, padx=5, pady=5)340 reset_btn = Button(RF, text="RESET", command=resetURLField,341 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)342 reset_btn.grid(row=1, column=0, padx=5, pady=5)343 back_btn = Button(RF, text="BACK", command=lambda: reinstate(rt, retrieve_pwd),344 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=26)345 back_btn.grid(row=2, column=0, padx=5, pady=5)346 your_password_txt = Label(347 LF, text='Your Password:', fg="steel blue", font=('arial', 11, 'bold'))348 your_password_txt.grid(row=4, column=0, padx=10, pady=10)349 your_password = Label(350 LF, text='', fg="steel blue", font=('arial', 11, 'bold'), width=16)351 your_password.grid(row=4, column=1, padx=10, pady=10)352353 retrieve_pwd.mainloop()354355356def retrievePasswordFromDB():357 dbcursor.execute(358 'SELECT password FROM accounts WHERE url = %s', (txtURL.get(),))359 result = dbcursor.fetchone()360 if result != None:361 your_password.config(text=result)362 copyToClipboard("Password Manager Notifier",363 "Password Copied to Clipboard Successfully!", your_password.cget('text'))364 else:365 notifier.show_toast("Password Manager Notifier", "Record Not Found!",366 duration=10, threaded=True, icon_path='password.ico')367368369def resetURLField():370 url_text.set("")371372373def showAllPasswords(rt):374 # retrieve all the passwords stored in DB and display375 rt.withdraw()376 show_pwds = Toplevel(rt)377 show_pwds.config(bg="white")378 show_pwds.title("SHOW ALL PASSWORDS")379 show_pwds.geometry("1000x500+0+0")380 show_pwds.resizable(False, False)381 url_text = StringVar()382 Tops = Frame(show_pwds, width=1000, height=50, bd=16, relief="raise")383 Tops.pack(side=TOP)384 mainTitle = Label(Tops, text='ALL PASSWORDS', borderwidth=1, relief="groove",385 fg="steel blue", font=('arial', 15, 'bold'), bd=10, anchor='w')386 mainTitle.grid(row=0, column=0)387 CF = Frame(show_pwds, width=1000, height=500, bd=16, relief="raise")388 CF.pack(side=TOP)389 email = Label(CF, text="Email", bg="steel blue",390 borderwidth=2, relief="raised", width=14)391 email.grid(row=0, column=0, padx=10, pady=10)392 password = Label(CF, text="Password",393 bg="steel blue", borderwidth=2, relief="raised", width=14)394 password.grid(row=0, column=1, padx=10, pady=10)395 username = Label(CF, text="Username",396 bg="steel blue", borderwidth=2, relief="raised", width=14)397 username.grid(row=0, column=2, padx=10, pady=10)398 url = Label(CF, text="URL / App name",399 bg="steel blue", borderwidth=2, relief="raised", width=14)400 url.grid(row=0, column=3, padx=10, pady=10)401402 all_pwds = retrieveAllPasswords()403 for index, pwd in enumerate(all_pwds):404 Label(CF, text=pwd[0],borderwidth=1, width=24).grid(row=index+1, column=0)405 Label(CF, text=pwd[1],borderwidth=1, width=24).grid(row=index+1, column=1)406 Label(CF, text=pwd[2],borderwidth=1, width=24).grid(row=index+1, column=2)407 Label(CF, text=pwd[3],borderwidth=1, width=24).grid(row=index+1, column=3)408 409 back_btn = Button(CF, text="BACK", command=lambda: reinstate(rt, show_pwds),410 pady=6, bd=8, fg="steel blue", font=('arial', 10, 'bold'), width=20)411 back_btn.grid(row=2, column=5, padx=10, pady=10)412413 show_pwds.mainloop()414415416def retrieveAllPasswords():417 dbcursor.execute('SELECT * FROM accounts')418 return dbcursor.fetchall()419420def reinstate(rt, pwd_manager):421 rt.deiconify()422 pwd_manager.destroy()423424425426if __name__ == "__main__": ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful