Thursday, February 17, 2011

Forget Password


Forgetpassword.aspx

<table border="0" style=" background-color:#FAFFF8; font-family:Arial; font-size:12px" width="100%" cellspacing="5px">
        <tr>
            <td style="height: 20px; text-align:left;">
                <b>Forgot Password</b>
            </td>
        </tr>
        <tr>
            <td style="height: 20px;">
                <asp:Panel ID="pnlinfo" runat="server" class="pnlinfo">
                  <asp:Label ID="lblinfo" runat="server"></asp:Label>
                  </asp:Panel>
                </td>
        </tr>
       <tr><td>Just enter the Email-ID with which you registered on ballgrinder.com and click Submit. Your password will be sent to the email address entered below. Please do enter the email address associated with your account.</td></tr>
       <tr><td>
           <asp:TextBox ID="txtmailid" runat="server" style="width:300px"
               CausesValidation="True"></asp:TextBox>
           <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  ValidationGroup="a"
               ControlToValidate="txtmailid" ErrorMessage="Please Enter your email id"></asp:RequiredFieldValidator>
           <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" TargetControlID="RequiredFieldValidator1" >
           </cc1:ValidatorCalloutExtender>
       </td></tr>
       <tr><td>
        
           </td></tr>
       <tr><td>
           <asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" ValidationGroup="a"/>
           </td></tr>
    </table>


Forgetpassword.aspx.cs

protected void Button1_Click(object sender, EventArgs e)
    {
        getpassword();
    }
    public void getpassword()
    {
        string str = "select username,password from tablename where username='"+txtmailid.Text+"' or email='"+txtmailid.Text+"'";
        SqlConnection con = new SqlConnection(_ConnectionString);
            con.Open();
            SqlTransaction trans = con.BeginTransaction();

SqlCommand cmd = con.CreateCommand();
            cmd.Transaction = trans; 
        try
        {
            cmd.CommandText = str;
                 DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string username = ds.Tables[0].Rows[0][0].ToString();
                string password = ds.Tables[0].Rows[0][1].ToString();
                sendMailNow(username, password, txtmailid.Text);

                pnlinfo.Visible = true;
                pnlinfo.BackColor = System.Drawing.ColorTranslator.FromHtml("#EEF4FC");
                pnlinfo.BorderColor = System.Drawing.ColorTranslator.FromHtml("#7FB0E0");
                pnlinfo.BorderWidth = 1;
                lblinfo.Text = "Your Password has been sucessfully sent to your email address.";
                txtmailid.Text = "";
            }
            else
            {
                pnlinfo.Visible = true;
                pnlinfo.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFDDDD");
                pnlinfo.BorderColor = System.Drawing.ColorTranslator.FromHtml("#F26060");
                pnlinfo.BorderWidth = 1;
                lblinfo.Text = "You need to create a new account.";
            }
 trans.Commit();
        }
        catch (Exception ex)
        {
           
trans.Rollback();
        }
    }
    public void sendMailNow(string username, string password, string email)
    {
       
            // Code to send mail

        }

No comments:

Post a Comment

Total Pageviews