Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team

I have a logic that authenticate user login, but its failing to login it happens when i try to use forgot password. How can i prevent this from happening?

What I have tried:

C#
<pre>public Task SendAsync(IdentityMessage message)
        {
            // Plug in your email service here to send an email.
            var mailMessage = new MailMessage();
            mailMessage.To.Add(new MailAddress(message.Destination));
            mailMessage.From = new MailAddress("gcobanim@mandela.ac.za");
            mailMessage.Subject = message.Subject;
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = message.Body;
            using (var smtp = new SmtpClient())
            {
                var credential = new NetworkCredential
                {
                    UserName = "ggcobani@gmail.com",
                    Password = "Telkom35@@"
                };
                try
                {
                    smtp.Host = "smtp.gmail.com";
                    smtp.Port = 587;
                    smtp.EnableSsl = true;
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials = credential;
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.Send(mailMessage);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return Task.FromResult(0);
        }
    }
Posted
Updated 30-Nov-20 22:05pm
Comments
Richard Deeming 1-Dec-20 4:02am    
I hope that's not your real GMail credentials you've just posted to a public forum! 🤦‍♂️

If it is, I suggest you change your password immediately, and check all of your settings to make sure nobody has changed anything.
gcogco10 1-Dec-20 4:03am    
Richard they are not, what need to change here so i can make necessary changes

1 solution

You need to create an app password so that your application can bypass 2FA:
Sign in with App Passwords - Google Account Help[^]

If you're not using 2FA, you could turn on the "less secure apps" option[^], but it's not recommended.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900