我在ado.net上忘记了使用电子邮件的密码 [英] I forget password using email in ado.net

查看:78
本文介绍了我在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)

解决方案

你没有添加参数名 @Email 的SqlParameter 到您的 SqlCommand



但是:



你的方法是危险的!您应该从不在您的数据库中以纯文本形式存储密码!



请在此阅读以了解如何正确操作:



安全密码认证简单解释 [ ^ ]



Troy Hunt:您想要了解的有关构建安全密码重置功能的所有内容 [ ^ ]


您好,

您忘记传递参数@ SP中的电子邮件。



试试这个

 command.Parameters.AddWithValue(   @ Email  passyouremailaddress); 


查看您的查询

  string  strSelect =   SELECT Fullname,Password FROM registration WHERE Email =  @Email ; 



您已声明参数 @Email 但未传递任何值

你需要类似

 command.Parameters.AddWithValue(  @Email,电子邮件); 



在尝试

 connection.Open();  

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 an SqlParameter for the parameter name @Email to your SqlCommand.

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 query

string strSelect = "SELECT Fullname,Password FROM registration WHERE Email = @Email";


You've declared a parameter @Email but have not passed in any value
You need something like

command.Parameters.AddWithValue("@Email", Email);


before you attempt to do

connection.Open();


这篇关于我在ado.net上忘记了使用电子邮件的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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