#ImportError: attempted relative import with no known parent package Issue
5 messages · Page 1 of 1 (latest)
I also am trying to add an 2FA system onto the code but I have no idea how to implement it into his web app
user = User.query.filter_by(email=email).first()
if user:
if check_password_hash(user.password, password):
auth_code = str(random.randint(100000, 999999))
subject = "Authenication Code"
body = """
'Subject: Authentication Code\n\nYour authentication code is {auth_code}.'
"""
em = EmailMessage()
em ['From'] = sender_email
em ['To'] = recipient_email
em ['Subject'] = subject
em.set_content(body)
context = ssl.create_default_context()
with smtplib.SMTP_SSL('smtp.gmail.com',465, context=context) as smtp:
smtp.login(sender_email,sender_password)
smtp.sendmail(sender_email,recipient_email, em.as_string())
root = tk.Tk()
root.withdraw()
attempts = 0
while attempts < 5:
user_input = tk.simpledialog.askstring(title="Authentication Code", prompt="Please enter the authentication code:")
if user_input == auth_code:
messagebox.showinfo(title="Success", message="Authentication successful!")
login_user(user, remember=True)
return redirect(url_for('views.home'))
else:
messagebox.showerror(title="Error", message="Authentication failed! Try again")
attempts += 1
if attempts >= 5:
messagebox.showerror(title="Error", message="Too many failed authentication attempts. Exiting program.")
exit()
else:
flash('Incorrect password, try again.', category='error')
else:
flash('Email does not exist.', category='error')```