如何通过asp.net和C#中的Gmail服务器忘记密码 [英] how to forget password through gmail server in asp.net and c#
本文介绍了如何通过asp.net和C#中的Gmail服务器忘记密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编码如何通过gmail发送电子邮件.
首先,我知道电子邮件ID.我通过电子邮件忘记密码,我将获得密码.首先,我需要检查邮件ID是否在我们的数据库中.如果有,我将通过gmail服务器发送该密码,可以帮助我解决这个问题
解决方案
Don''t.
切勿存储密码.而是将其重置为随机值,然后通过电子邮件将其发送给用户,并带有指向更改密码"页面的链接.
以任何可读形式存储密码是个坏主意-问索尼!
尝试一下
公共 字符串 GetRandomString( int 长度) { System.Random rnd = 新 Random(); // 字符串charPool ="abc890defghijkl1234mnopqrstuvwxyz567"; 字符串 charPool = " ; System.Text.StringBuilder rs = 新 System.Text.StringBuilder(); 同时(长度-> 0 ) rs.Append(charPool [( int )(rnd.NextDouble()* charPool.Length)]);; 返回 rs.ToString(); }
或使用Guid
获取随机字符串
尝试一下
if(true) { MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" ); MailAddress mailto = new MailAddress ( "tomail@gmail.com" ); MailMessage newmsg = new MailMessage ( mailfrom, mailto ); newmsg.Subject = "Subject of Email"; newmsg.Body = "Body(message) of email"; ////For File Attachment, more file can also be attached //Attachment att = new Attachment ( "G:\\code.txt" ); //newmsg.Attachments.Add ( att ); SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 ); smtps.UseDefaultCredentials = false; smtps.Credentials = new NetworkCredential ( "mail@gmail.com", "pwd" ); smtps.EnableSsl = true; smtps.Send ( newmsg ); } else Label.Text="the email id is does not exist";
hi
i need coding how to send email through gmail.
first i know email id.i forget my password through email i will get password.first i need to check that mail id is in our database or not.if its there i will send that password through gmail server could help me for this
解决方案
Don''t.
Never store the password. Instead, reset it to a random value, and email that to the user instead, with a link to the "Change password" page.
Storing passwords in any readable form is a bad idea - ask Sony!
Try this
public string GetRandomString(int length) { System.Random rnd = new Random(); //string charPool = "abc890defghijkl1234mnopqrstuvwxyz567"; string charPool = "ABC890DEFGHIJKL1234MNOPQRSTUVWXYZ567"; System.Text.StringBuilder rs = new System.Text.StringBuilder(); while (length-- > 0) rs.Append(charPool[(int)(rnd.NextDouble() * charPool.Length)]); return rs.ToString(); }
or useGuid
to get a random string
try this
if(true) { MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" ); MailAddress mailto = new MailAddress ( "tomail@gmail.com" ); MailMessage newmsg = new MailMessage ( mailfrom, mailto ); newmsg.Subject = "Subject of Email"; newmsg.Body = "Body(message) of email"; ////For File Attachment, more file can also be attached //Attachment att = new Attachment ( "G:\\code.txt" ); //newmsg.Attachments.Add ( att ); SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 ); smtps.UseDefaultCredentials = false; smtps.Credentials = new NetworkCredential ( "mail@gmail.com", "pwd" ); smtps.EnableSsl = true; smtps.Send ( newmsg ); } else Label.Text="the email id is does not exist";
这篇关于如何通过asp.net和C#中的Gmail服务器忘记密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文