我在ado.net上忘记了使用电子邮件的密码 [英] I forget password using email in ado.net
问题描述
public ActionResult ForegetPassord(RegisterModel s)
string Email = Request.Form [ Email];
string 消息= Request.Form [ 消息跨度>];
string strConnection = Data Source = mehaknaz; Initial Catalog = Registration; Integrated Security = True;
string strSelect = SELECT全名,密码FROM注册WHERE电子邮件= @Email;
SqlConnection connection = new SqlConnection(strConnection);
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = strSelect;
DataSet dsPwd = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter(command);
connection.Open();
dAdapter.Fill(dsPwd);
connection.Close();
if (dsPwd.Tables [ 0 ]。Rows.Count > 0 )
{
string MailingAddress = ConfigurationManager.AppSettings [ MailingAddress]。ToString();
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(MailingAddress,Email);
SmtpClient client = new SmtpClient();
message.Subject = 忘记;
message.IsBodyHtml = true ;
message.Body = FullName: + dsPwd.Tables [ 0 ]。行[ 0 ] [ FullName] + < br>< br>密码: + dsPwd.Tables [ 0 ]。行[ 0 ] [ 密码] + <峰; br><峰; br> 中跨度>;
client.Host = ConfigurationManager.AppSettings [ MailServerName]。ToString();
client.Port = 587 ;
System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential(
MailingAddress
,ConfigurationManager.AppSettings [ 密码]。ToString()
);
client.Credentials = basicCredential;
client.Send(message);
Response.Write( < script LANGUAGE ='JavaScript'> alert('Email Sent') < /脚本>中跨度>);
}
else
{
Response.Write( < script LANGUAGE ='JavaScript'> alert('Email Not Register')< / script>);
}
return 查看;
}
我的尝试:
i有一个错误..如何解决..如果你忘记了passwpord代码然后提供
'/'应用程序中的服务器错误。 />
必须声明标量变量@Email。
描述:执行期间发生了未处理的异常当前的网络请求。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Data.SqlClient.SqlException:必须声明标量变量@Email。
来源错误:
第113行:SqlDataAdapter dAdapter = new SqlDataAdapter(命令);
第114行:connection.Open();
第115行:dAdapter.Fill(dsPwd);
第116行:connection.Close();
第117行:if(dsPwd.Tables [0] .Rows.Count> 0)
你没有添加参数名
到您的SqlCommand
。
但是:
你的方法是危险的!您应该从不在您的数据库中以纯文本形式存储密码!
请在此阅读以了解如何正确操作:
安全密码认证简单解释 [ ^ ]
Troy Hunt:您想要了解的有关构建安全密码重置功能的所有内容 [ ^ ]
您好,
您忘记传递参数@ SP中的电子邮件。
试试这个
command.Parameters.AddWithValue( @ Email, passyouremailaddress);
查看您的查询string strSelect = SELECT Fullname,Password FROM registration WHERE Email = @Email ;
您已声明参数
你需要类似
command.Parameters.AddWithValue( @Email,电子邮件);
在尝试connection.Open(); $之前p $ p>
public ActionResult ForegetPassord(RegisterModel s)
{
string Email = Request.Form["Email"];
string Msg = Request.Form["Message"];
string strConnection = "Data Source=mehaknaz;Initial Catalog=Registration;Integrated Security=True";
string strSelect = "SELECT Fullname,Password FROM registration WHERE Email = @Email";
SqlConnection connection = new SqlConnection(strConnection);
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = strSelect;
DataSet dsPwd = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter(command);
connection.Open();
dAdapter.Fill(dsPwd);
connection.Close();
if(dsPwd.Tables[0].Rows.Count > 0 )
{
string MailingAddress = ConfigurationManager.AppSettings["MailingAddress"].ToString();
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(MailingAddress, Email);
SmtpClient client = new SmtpClient();
message.Subject = "forget";
message.IsBodyHtml = true;
message.Body = "FullName: " + dsPwd.Tables[0].Rows[0]["FullName"] + "<br><br>Password: " + dsPwd.Tables[0].Rows[0]["Password"] + "<br><br>";
client.Host = ConfigurationManager.AppSettings["MailServerName"].ToString();
client.Port = 587;
System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential(
MailingAddress
, ConfigurationManager.AppSettings["Password"].ToString()
);
client.Credentials = basicCredential;
client.Send(message);
Response.Write("<script LANGUAGE='JavaScript'>alert('Email Sent')</script>");
}
else
{
Response.Write("<script LANGUAGE='JavaScript'>alert('Email Not Register')</script>");
}
return View(s);
}
What I have tried:
i Have an errror ..how to resolve..if you have forget passwpord code then provide
Server Error in '/' Application.
Must declare the scalar variable "@Email".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@Email".
Source Error:
Line 113: SqlDataAdapter dAdapter = new SqlDataAdapter(command);
Line 114: connection.Open();
Line 115: dAdapter.Fill(dsPwd);
Line 116: connection.Close();
Line 117: if(dsPwd.Tables[0].Rows.Count > 0 )
You didn't add anSqlParameter
for the parameter nameSqlCommand
.
BUT:
Your approach is dangerously wrong! You should NEVER store passwords as plain text in your database!
Please read up here to learn how to do it right:
Secure Password Authentication Explained Simply[^]
Troy Hunt: Everything you ever wanted to know about building a secure password reset feature[^]
Hello ,
You forgot to pass the parameter @Email in SP .
Try this
command.Parameters.AddWithValue("@Email", "passyouremailaddress");
Look your querystring strSelect = "SELECT Fullname,Password FROM registration WHERE Email = @Email";
You've declared a parameter
You need something like
command.Parameters.AddWithValue("@Email", Email);
before you attempt to doconnection.Open();
这篇关于我在ado.net上忘记了使用电子邮件的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!