Skip to content
Advertisement

In Python how do I test that the gmail password is correct?

I want to test whether the password entered by the user of his google account is correct or not, but I am always getting INCORRECT as an output

How do I perform this?

Before asking this question I’ve tried :

import smtplib as s

ID = input("ENTER YOUR MAIL ID")
PASSW = input("pass")

server = s.SMTP("smtp.gmail.com", 587)
server.starttls()

a = server.login(ID,PASSW)

if a == True:
    print("CORRECT")
else:
    print("INCORRECT")

server.quit()

Advertisement

Answer

This should work just make sure Less secure app is enabled

import smtplib as s

ID = '' #your mail
PASSW = input("pass : ")

server = s.SMTP("smtp.gmail.com", 587)
server.starttls()
try:
    server.login(ID,PASSW)
except SMTPAuthenticationError:
    print("Password is wrong")

server.quit()
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement