Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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 )
Posted
Updated 9-Mar-16 23:31pm

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[^]
 
Share this answer
 
Hello ,
You forgot to pass the parameter @Email in SP .

Try this
C#
command.Parameters.AddWithValue("@Email", "passyouremailaddress");
 
Share this answer
 
Look your query
C#
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
C#
command.Parameters.AddWithValue("@Email", Email);

before you attempt to do
C#
connection.Open();
 
Share this answer
 
Comments
Mehak Naaz 10-Mar-16 5:44am    
again error..
Server Error in '/' Application.

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required
CHill60 10-Mar-16 5:50am    
That's a completely different problem - you haven't passed the authentication details through to the SMTP server, OR the credentials you supplied were incorrect (probably the former though)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900