0

I am writing this function in python with the Tkinter module.

I want the user to enter the password when he/she presses show. But I only want to ask the user to enter a password if the last password was asked 15 minutes ago.

    def show(self):

    if self.showButton['text'] == "hide":
        self.showButton['text'] = "show"
        self.password_text_label.grid_forget()
        self.password_display_label.grid(row=6 + self.count, column=2, sticky=E, padx=5)
    else:
        popupWindow(root)   # this will ask for master-password if you want to see the password (Another Layer of security)
        self.showButton['text'] = "hide"
        self.password_display_label.grid_forget()
        self.password_text_label.grid(row=6 + self.count, column=2, sticky=E, padx=5)
vandit vasa
  • 413
  • 4
  • 20

1 Answers1

1

create a variable and store the last login time, then compare it to the current time. To get time difference you can use relativedelta

Here is an example:

from tkinter import *
from datetime import datetime
from dateutil.relativedelta import relativedelta


minutes = 15

def askPasswd():
    global lastAsked
 
    if lastAsked is None or relativedelta(datetime.now(), lastAsked).minutes  >= minutes:
        lastAsked = datetime.now()

        top = Toplevel()
        Label(top, text='Password').pack()
        Entry(top).pack()
        
root = Tk()

lastAsked = None

askBtn = Button(root, text='Ask', command=askPasswd)
askBtn.pack()

root.mainloop()
JacksonPro
  • 3,135
  • 2
  • 6
  • 29