I have a code that works for recovering a user’s password in case they have forgotten it. This is what I currently have:
from tkinter import *
from PIL import Image, ImageTk
import tkinter as tk
from tkinter import messagebox
import pymysql
windows = Tk()
windows.geometry('500x400+500+100')
windows.attributes('-transparentcolor', 'red')
windows.title('Simple Coding Style')
def back():
windows.destroy()
import loginpg
# def submit():
# if usernameEntry.get() == '' or emailEntry.get() == '' or NewpasswordEntry.get() == '' or confirmpasswordEntry.get() == '':
# messagebox.showerror('Error', "Entry fields must be entered")
# return
# elif NewpasswordEntry.get() != confirmpasswordEntry.get():
# messagebox.showerror('Error', "Passwords don't match")
# return
# else:
# db = pymysql.connect(host='127.0.0.1', user='root', password='password', database='test')
# mycursor = db.cursor()
# query = 'select * from personaldata where email=%s'
# mycursor.execute(query, (emailEntry.get()))
# role=mycursor.fetchone() #fetch the existing data
# if role==None:
# messagebox.showerror('Error', 'Incorrect email or password')
# else:
# query='update personaldata set passwrd=%s where email=%s'
# mycursor.execute(query, (NewpasswordEntry.get(),emailEntry.get()))
# db.commit()
# db.close()
# messagebox.showinfo('Success', 'Please login with New password')
# windows.destroy()
def fetch_old_password(email):
db = pymysql.connect(host='127.0.0.1', user='root', password='password', database='test')
mycursor = db.cursor()
query = 'SELECT passwrd FROM personaldata WHERE email=%s'
mycursor.execute(query, (email,))
result = mycursor.fetchone()
db.close()
return result[0] if result else None
def submit():
email = emailEntry.get()
old_password = fetch_old_password(email)
if not old_password:
messagebox.showerror('Error', 'Email not found')
else:
messagebox.showinfo('Old Password', f'Your old password is: {old_password}')
windows.destroy()
frame=Frame(windows, width=540, height=640, bg='light blue', bd=8)
frame.place(x=0,y=0)
#labels on window
heading =Label(frame, text='FORGOT PASSWORD', fg='black', bg='light blue', font=('Calibre', 15, 'bold'))
heading.place(x=110, y=3)
usernameImage=PhotoImage(file='padlock.png')
usernameLabel=Label(frame, image=usernameImage)
usernameLabel.place(x=45, y=3)
emaillbl = Label(frame, text='Email:', fg='black', bg='light blue', font=('Calibre', 15, 'bold'))
emaillbl.place(x=10, y=140)
emailEntry=Entry(frame, width=30, borderwidth=2)
emailEntry.place(x=250, y=140)
# confirmpasswordEntry=Entry(frame, width=30, borderwidth=2)
# confirmpasswordEntry.place(x=250, y=220)
bckbtn = Button(frame, text='<<', width=7, borderwidth=5, height=2, bg='white', fg='black', cursor='hand2', border=2,
command=back)
bckbtn.place(x=10, y=300)
submit1btn = Button(frame, text='Submit', width=15, height=2, bg='#7f7fff',fg='white', cursor='hand2', border=2, borderwidth=5, font=('#57a1f8', 16, 'bold'), command=submit)
submit1btn.place(x=130, y=280)
windows.resizable(False,False)
windows.mainloop()
My code is designed for a desktop app. At the moment, it only sends a message to the user directly but I want it so that the recovered password is sent to their email. What should I use or create to apply this feature?