change password control for asp.net based on SQl server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • parshupooja
    New Member
    • Jun 2007
    • 159

    change password control for asp.net based on SQl server

    Hi

    I have created a login page which has user name n password. After entering values it authenticate from SQL Server and if it is correct, it forwards to designated page otherwise shows invalid login message. i have 5000 users in my system, so i opted this way. Now i want ot create a button on login page which shows change password. I want to replace my old password field value with new password field. I don't want to create another column and don't want to use asp web administration tool

    any help will be appreciated

    thank you
  • christopherpond
    New Member
    • Jul 2007
    • 26

    #2
    Have you looked at the at the login controls provided in ASP.Net 2.0? They are simple to use. A control that may be useful to you could be the Password Recovery Web Control.

    Christopher Pond
    Innovative Website Development

    Comment

    • christopherpond
      New Member
      • Jul 2007
      • 26

      #3
      Check out the membership APIs as well. All this functionality is build into ASP.net 2.0

      Check out this Article

      Christopher Pond
      Innovative Website Development

      Comment

      • parshupooja
        New Member
        • Jun 2007
        • 159

        #4
        Hi,

        thank You for response, but i do not want to use SQLmembershippr ovider. I want to create simple change password tool which asks for current password and new password and based on that it should replace old password with new password in database. I have only 3 columns in database - user, password and email.

        thank You

        Comment

        • christopherpond
          New Member
          • Jul 2007
          • 26

          #5
          I would add a form with 3 text boxes as you'll see in many web sites.,

          Enter Old Password ()
          Enter New Password()
          Confirm New Password()

          Then in SQL(psedo Code) Update Table set Password= NewPassword where Password = OldPassword And Email = Email.

          Does that help?

          Comment

          • parshupooja
            New Member
            • Jun 2007
            • 159

            #6
            thank you, it did work out but when i am trying to put validators on textboxes, it doesn't work

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Originally posted by parshupooja
              thank you, it did work out but when i am trying to put validators on textboxes, it doesn't work
              What isn't working on the validators?

              Comment

              • parshupooja
                New Member
                • Jun 2007
                • 159

                #8
                Its working now, mistakenly I used Comparevalidato r on both textboxes(New Password and Confirm New Password), it should be on one only.

                Code:
                <table style="text-align:right; width:auto;">
                        <tr><asp:ValidationSummary ID="ValSumm" runat="server" /><br /><asp:CompareValidator ID="ComValCNP" runat="server" ControlToCompare="NewPassword" ControlToValidate="ConfirmNewPassword">Password Should Match</asp:CompareValidator></tr><tr>
                            <td>
                                <asp:Label ID="Label1" runat="server" Text="Current Password"></asp:Label></td>
                            <td>
                                <asp:TextBox ID="CurrentPassword" runat="server" TextMode="Password" />
                                <asp:RequiredFieldValidator ID="ReqFVCP" runat="server" ControlToValidate="CurrentPassword"
                                    ErrorMessage="Please Enter Current Password">*</asp:RequiredFieldValidator></td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="Label2" runat="server" Text="New Password"></asp:Label></td>
                            <td>
                    <asp:TextBox ID="NewPassword" runat="server" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="ReqFVNP" runat="server" ErrorMessage="Please Enter New Password" ControlToValidate="NewPassword">*</asp:RequiredFieldValidator>
                    </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="Label3" runat="server" Text="Confirm New Password"></asp:Label></td>
                            <td>
                    <asp:TextBox ID="ConfirmNewPassword" runat="server" TextMode="Password"></asp:TextBox><asp:RequiredFieldValidator ID="ReqFVCNP" runat="server" ErrorMessage="Please Confirm New Password" ControlToValidate="ConfirmNewPassword">*</asp:RequiredFieldValidator>
                     
                    </td>
                        </tr>
                        <tr>
                            <td>
                    <asp:Button ID="Button1" runat="server"  Text="Save" OnClick="Button1_Click" /></td>
                   <td> <asp:Button ID="refresh" runat="server"  Text="Refresh" OnClick="refresh_Click" /></td>        
                        </tr>
                    </table>
                code behind
                Code:
                protected void Button1_Click(object sender, EventArgs e)
                   {
                       
                       string oldPassword = CurrentPassword.Text;
                        string newPassword = NewPassword.Text;
                        bool result = ChangeUserPassword(oldPassword, newPassword);
                   }
                   private bool ChangeUserPassword(string oldPassword, string newPassword)
                   {
                
                        string query = "ChangePassword";
                        //string query = @"Update Users set Password = @NewPassword where Password = @OldPassword";
                        string connectionString = (string)ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                        SqlConnection myConnection = new SqlConnection(connectionString);
                        SqlCommand myCommand = new SqlCommand(query, myConnection);
                        myCommand.CommandType = CommandType.StoredProcedure;
                        myCommand.Parameters.AddWithValue("@NewPassword", newPassword);
                        myCommand.Parameters.AddWithValue("@OldPassword", oldPassword);
                
                        myConnection.Open();
                        string userId = (string)myCommand.ExecuteScalar();
                
                        //string userId = (string)  myCommand.ExecuteScalar();
                        myConnection.Close();
                
                        if (userId != null && userId.Length > 0)
                            return true;
                        else return false;
                    }

                Comment

                Working...