top of page

Password Manager

  • Writer: 라임 샹큼
    라임 샹큼
  • Mar 30
  • 2 min read

import tkinter

from tkinter import messagebox

from tkinter import PhotoImage

import random


# ---------------------------- PASSWORD GENERATOR ------------------------------- #

big_alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

small_alphabet = [letter.lower() for letter in big_alphabet]

alphabet = big_alphabet+small_alphabet


def generate_password():

    password_list = []

    final_password_list = []


    password_num_length = random.randint(5,6)

    password_letter_length = random.randint(3,6)

    

    for length in range(password_num_length):

        password_list.append(str(random.randint(1,9)))

    for length in range(password_letter_length):

        password_list.append(random.choice(alphabet))

    for length in range(len(password_list)):

        final_password_list.append(random.choice(password_list))

        final_password = ''.join(final_password_list)

    password_input.insert(0,final_password)


# ---------------------------- SAVE PASSWORD ------------------------------- #



def save():

    website_ouput = website_input.get()

    email_output = user_input.get()

    password_output = password_input.get()

    if len(website_ouput)<1 or len(email_output)<1 or len(password_output)<1:

        messagebox.showinfo(message = 'Please do not leave any blanks')

    else:

        is_ok =messagebox.askokcancel(title = 'title', message = f'These are the details: Website:{website_ouput}\nEmail:{email_output}\nPassword:{password_output}')

        if is_ok:

            with open('data.txt','a') as data:

                data.write(f'{website_ouput} | {email_output} | {password_output}\n')

                website_input.delete(0,'end')

                # user_input.delete(0, '@gmail.com')

                password_input.delete(0, 'end')


# ---------------------------- UI SETUP ------------------------------- #

window = tkinter.Tk()

window.title('Password Manager')

window.config(padx=60, pady = 60)


#put image inside

image = PhotoImage(file = 'logo.png')

canvas = tkinter.Canvas(height = 200, width=200)

canvas.create_image(100,100, image = image)

canvas.grid(column = 1, row =0)


#website label

website = tkinter.Label(text = 'Website:')

website.grid(column = 0, row= 1)


#website input

website_input = tkinter.Entry(width=35)

website_input.grid(column = 1, row = 1, columnspan=2)

website_input.focus()


#Email/username label

user = tkinter.Label(text = 'Email/Username:')

user.grid(column = 0, row = 2)


#user input

user_input =tkinter.Entry(width = 35)

user_input.grid(column = 1, row = 2, columnspan=2)

user_input.insert(0,'@gmail.com')


#password label

password = tkinter.Label(text = "Password:")

password.grid(column = 0, row = 3)


#password input

password_input = tkinter.Entry(width = 18)

password_input.grid(column = 1, row = 3)


#generate password button

generate_password = tkinter.Button(text = 'Generate Password',command=generate_password)

generate_password.grid(column = 2, row =3)


#add button

add = tkinter.Button(text ='Add', width=34,command = save)

add.grid(column = 1, row = 4, columnspan=2)





window.mainloop()


What I learned:

  • columnspan attribute possible in grid():

    decides how many columns long your object takes up

  • ___.focus():

    this will bring the mouse right to the entry box

  • _____.insert(index, text):

    can fill out a little bit of the entry for you, in this case perhaps frequently used email

  • ___.delete(start index, 'end'-end index):

    deletes all that was in the entry blank.

  • To create a messagebox that checks stuff, have to import messagebox from tkinter. Is not a class.

  • messagebox.askokcancel(title = 'title', message = f'These are the details: \nEmail:{email_output}\nPassword:{password_output}')

    #is true or false

  • pyperclip module:

    allows for automatic copying. can use for copying password without manually copying it.

    import pyperclip

    pyperclip.copy(what I want to copy)

 
 
 

Recent Posts

See All
Stock market price alerter

Lately I’ve been getting API data from existing data and using it to get actual live data. This is done by importing requests.  This was...

 
 
 
Making a better quiz ui

I reencountered classes again. I remember I had a a hard time learning how classes were different from simply defining functions. It was...

 
 
 
Getting quotes and displaying them

from tkinter import * import requests def get_quote():     quote_url = requests.get(url=' https://api.kanye.rest ')     quote_json =...

 
 
 

Comments


© 2024 by GifTED. Powered and secured by Wix

bottom of page