发送链接给用户更改密码 [英] Send a link to Change Password to the User
本文介绍了发送链接给用户更改密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
注意:我没有使用会员资格.
在登录页面上,我想放置一个忘记密码"链接.因此,当用户单击链接时,将输入电子邮件地址和用户名,并将在数据库中对其进行验证.
然后,将向 ChangePassword.aspx 的链接发送给用户,该链接将在一天后过期.
如何创建此安全链接.
谢谢&问候,
Prathap.
Hi All,
Note: ''I am not using Membership.
On the login page I would like to place a Forgot Password link. So when the User clicks on the link Email Address and Username will be entered which will be verified in the database.
Then a link is send to the User for the ChangePassword.aspx which will expire in one day.
How to Create this link which is secure.
Thanks & Regards,
Prathap.
推荐答案
HELLO
HELLO
//Create Connection String And SQL Statement
string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string strSelect = "SELECT UserName,Password FROM Users WHERE Email = @Email";
SqlConnection connection = new SqlConnection(strConnection);
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = strSelect;
SqlParameter email = new SqlParameter("@Email", SqlDbType.VarChar, 50);
email.Value = txtEmail.Text.Trim().ToString();
command.Parameters.Add(email);
//Create Dataset to store results and DataAdapter to fill Dataset
DataSet dsPwd = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter(command);
connection.Open();
dAdapter.Fill(dsPwd);
connection.Close();
if(dsPwd.Tables[0].Rows.Count > 0 )
{
MailMessage loginInfo = new MailMessage();
loginInfo.To.Add(txtEmail.Text.ToString());
loginInfo.From = new MailAddress("YourID@gmail.com");
loginInfo.Subject = "Forgot Password Information";
loginInfo.Body = "Username: " + dsPwd.Tables[0].Rows[0]["UserName"] + "<br><br>Password: " + dsPwd.Tables[0].Rows[0]["Password"] + "<br><br>";
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("YourGmailID@gmail.com", "YourGmailPassword");
smtp.Send(loginInfo);
lblMessage.Text = "Password is sent to you email id,you can now <a href="Login.aspx">Login</a>";
}
else
{
lblMessage.Text = "Email Address Not Registered";
}
}
否则,您可以发送重设密码链接,也可以使用自己的逻辑终止交易.
OR YOU CAN SEND RESET PASSWORD LINK AND YOU CAN IMPLIMENT YOUR OWN LOGIC TO EXPIRE THE LONK.
这篇关于发送链接给用户更改密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文