当您单击“忘记密码"时,如何通过邮件获取密码或创建新的密码链接 [英] when you are click on forget password then how to get password via mail or create new password link

查看:97
本文介绍了当您单击“忘记密码"时,如何通过邮件获取密码或创建新的密码链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您单击忘记密码",然后如何通过邮件获取密码或创建新的密码链接时????

when you are click on forget password then how to get password via mail or create new password link???

推荐答案

这取决于您存储密码的方式.
就个人而言,我会将它们存储为无法恢复的哈希(此处有一个提示:发送电子邮件在C#中(带有或不带有附件):通用例程. [ Membership.GeneratePassword方法 [
It depends on how you are storing passwords.
Personally, I would store them as hashes which cannot be recovered (There is a tip on this here: Password Storage: How to do it.[^]) , so I would create a new random password, and email it to the registered email address. There is a generic routine for that here: Sending an Email in C# with or without attachments: generic routine.[^]

There are two easy ways to generate a random password: I tend to use the Guid.NewGuid method, but you can also use the Membership.GeneratePassword Method[^] if you are using MembershipProviders.


公共静态int ForgotPassword(字符串uname,字符串电子邮件)
{
Mail_Forgotpassword密码=新的Mail_Forgotpassword();
System.Net.Mail.MailMessage obj =新的System.Net.Mail.MailMessage();
int boolReturnValue = 1;
password.strEmail =电子邮件;
password.strUserName = uname;
DataSet ds = new DataSet();
ds = password.GetPassword();
如果(ds.Tables [0] .Rows.Count> 0)
{
字符串FrstName = ds.Tables [0] .Rows [0] [5] .ToString();
FrstName = FrstName.Substring(0,1).ToUpper()+ FrstName.Substring(1).ToLower();
字符串姓氏= ds.Tables [0] .Rows [0] [6] .ToString();
LastName = LastName.Substring(0,1).ToUpper()+ LastName.Substring(1).ToLower();
字符串strName = ds.Tables [0] .Rows [0] [7] .ToString();
字符串strpwd = ds.Tables [0] .Rows [0] [8] .ToString();
SmtpClient serverobj = new SmtpClient();
serverobj.Credentials =新的NetworkCredential(ConfigurationManager.AppSettings ["Username"].ToString(),ConfigurationManager.AppSettings ["UserPass"].ToString());
serverobj.Port = System.Convert.ToInt32(ConfigurationManager.AppSettings ["Port"].ToString());
serverobj.Host = ConfigurationManager.AppSettings ["HostName"].ToString(); ;
serverobj.EnableSsl = false;
obj =新的System.Net.Mail.MailMessage();
obj.From =新MailAddress(ConfigurationManager.AppSettings ["Username"],"xyz.com",System.Text.Encoding.UTF8);
obj.To.Add(电子邮件);
obj.Priority = System.Net.Mail.MailPriority.High;
obj.Subject =密码恢复";
obj.Body =尊敬的" + FrstName +" + LastName +," +"\ n" +"\ n" +我们已经处理了您的密码检索请求.您的帐户详细信息如下所述" +"\ n"+" \ n"+"用户名:"+ strName +" \ n"+"密码:"+ strpwd +" \ n"+" \ n"+"请确保其安全"+" \ n"+" \ n"+"如有任何其他疑问/帮助,请发送电子邮件至abc@gmail.com"+" \ n"+" \ n"+" \ n"+"问候"+" \ n"+" xyz. com;
serverobj.Send(obj);
boolReturnValue = 1;

}
其他
{
boolReturnValue = 0;
}

return boolReturnValue;

}

在WEBCONFIG文件中,我们应该写入此代码

< appSettings>

<添加key ="HostName" value ="smtp.gmail.com"/>
< add key ="Port" value ="587"/>
<添加key ="EmailFrom" value ="abc@gmail.com"/>
<添加key ="Username" value ="anil"/>
<添加key ="UserPass" value ="kumar"/>
</appSettings>

< system.net>
< mailSettings>
< smtp from ="abc@gmail.com" deliveryMethod ="Network">
< network host ="mail.agilelearning.com" defaultCredentials ="true" userName ="anil" password ="kumar"/>
</smtp>
</mailSettings>
</system.net>




进行分析并尝试.

问候,

Anilkumar.D
public static int ForgotPassword(string uname, string email)
{
Mail_Forgotpassword password = new Mail_Forgotpassword();
System.Net.Mail.MailMessage obj = new System.Net.Mail.MailMessage();
int boolReturnValue = 1;
password.strEmail = email;
password.strUserName = uname;
DataSet ds = new DataSet();
ds = password.GetPassword();
if (ds.Tables[0].Rows.Count > 0)
{
string FrstName = ds.Tables[0].Rows[0][5].ToString();
FrstName = FrstName.Substring(0, 1).ToUpper() + FrstName.Substring(1).ToLower();
string LastName = ds.Tables[0].Rows[0][6].ToString();
LastName = LastName.Substring(0, 1).ToUpper() + LastName.Substring(1).ToLower();
string strName = ds.Tables[0].Rows[0][7].ToString();
string strpwd = ds.Tables[0].Rows[0][8].ToString();
SmtpClient serverobj = new SmtpClient();
serverobj.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["Username"].ToString(), ConfigurationManager.AppSettings["UserPass"].ToString());
serverobj.Port = System.Convert.ToInt32(ConfigurationManager.AppSettings["Port"].ToString());
serverobj.Host = ConfigurationManager.AppSettings["HostName"].ToString(); ;
serverobj.EnableSsl = false;
obj = new System.Net.Mail.MailMessage();
obj.From = new MailAddress(ConfigurationManager.AppSettings["Username"], "xyz.com", System.Text.Encoding.UTF8);
obj.To.Add(email);
obj.Priority = System.Net.Mail.MailPriority.High;
obj.Subject = "Password Recovery";
obj.Body = "Dear " + FrstName + " " + LastName + "," + "\n" + "\n" + "We have processed your request for password retrieval. Your account details are as mentioned below" + "\n" + "\n" + "UserName :" + strName + "\n" + "Password :" + strpwd + "\n" + "\n" + "Please keep them safe" + "\n" + "\n" + "For any further queries/assistance kindly mail us at abc@gmail.com" + "\n" + "\n" + "\n" + "Regards," + "\n" + "xyz.com";
serverobj.Send(obj);
boolReturnValue = 1;

}
else
{
boolReturnValue = 0;
}

return boolReturnValue;

}

IN WEBCONFIG FILE WE SHOULD WRITE THIS CODE

<appSettings>

<add key="HostName" value="smtp.gmail.com" />
<add key="Port" value="587" />
<add key="EmailFrom" value="abc@gmail.com" />
<add key="Username" value="anil" />
<add key="UserPass" value="kumar" />
</appSettings>

<system.net>
<mailSettings>
<smtp from="abc@gmail.com" deliveryMethod="Network">
<network host="mail.agilelearning.com" defaultCredentials="true" userName="anil" password="kumar" />
</smtp>
</mailSettings>
</system.net>




analize and try this.

Regards,

Anilkumar.D


这篇关于当您单击“忘记密码"时,如何通过邮件获取密码或创建新的密码链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆