locked
Change password.. RRS feed

  • Question

  • User1908679259 posted

    hi


    i wont to change password via MS DB i wrote this code but it does not working with me can any one help me please



    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <script language="VB" runat="server">
        
       
        Dim cn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader
        Dim icount As Integer
        Dim str As String
        Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\login.mdb;")
            cn.Open()
            str = " SELECT REPLACE "(passwordTextBox.Text, TextBox1.Text, TextBox2.Text)
            'string stores the command and CInt is used to convert number to string
            cmd = New OleDbCommand(str, cn)
            icount = cmd.ExecuteNonQuery
            
            'displays number of records inserted
            
           
            cn.Close()
        End Sub
               
    End Class
     
        
        
        
    </script>

    <%@ Page Language="VB" %>

    <%@ Import Namespace="System.Data" %>

    <%@ Import Namespace="System.Data.OleDb" %>

    <%@ Import Namespace="System.Data" %>

    <%@ Import Namespace="System.Data.OleDb" %>

    <script language="VB" runat="server">

      

        Dim cn As OleDbConnection

        Dim cmd As OleDbCommand

        Dim dr As OleDbDataReader

        Dim icount As Integer

        Dim str As String




        Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)


            cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\login.mdb;")

            cn.Open()

            str = " SELECT REPLACE "(passwordTextBox.Text, TextBox1.Text, TextBox2.Text)

            'string stores the command and CInt is used to convert number to string

            cmd = New OleDbCommand(str, cn)

            icount = cmd.ExecuteNonQuery

              'displays number of records inserted

                           cn.Close()

        End Sub

               

    End Class


    <table class="style1">

        <tr>

            <td>

                password:    <td>

                <asp:TextBox ID="passwordTextBox" runat="server" 

                                        Text='<%# Bind("password") %>' 

                    EnableViewState="False" />

            </td>

            <td class="style2">

                &nbsp;</td>

            <td>

                &nbsp;</td>

        </tr>

        <tr>

            <td>

                New Password :</td>

            <td>

                <asp:TextBox ID="TextBox1" runat="server" EnableViewState="False" 

                                        Text='<%# Bind("password") %>'></asp:TextBox>

            </td>

            <td class="style2">

                &nbsp;&nbsp;&nbsp;

                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 

                                        ControlToValidate="TextBox1" ErrorMessage="New Password is Required" 

                                        ValidationGroup="Textbox1"></asp:RequiredFieldValidator>

                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</td>

            <td>

                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 

                                        ControlToValidate="TextBox1" 

                                        ErrorMessage="Must be at least 8 characters , contain at least one lower case letter, one upper case letter and one digit" 

                                        ValidationExpression="^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$" 

                                        ValidationGroup="TextBox1"></asp:RegularExpressionValidator>

            </td>

        </tr>

        <tr>

            <td>

                Retype New             Retype New Password :</td>

            <td>

                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("password") %>'></asp:TextBox>

            </td>

            <td class="style2">

                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 

                                        ControlToValidate="TextBox2" ErrorMessage="Retype Your New Password" 

                                        ValidationGroup="TextBox2"></asp:RequiredFieldValidator>

            </td>

            <td>

                <asp:CompareValidator ID="CompareValidator1" runat="server" 

                                        ControlToCompare="TextBox1" ControlToValidate="TextBox2" 

                                        ErrorMessage="Password not match" 

                    ToolTip="Password does not match"></asp:CompareValidator>

            </td>

        </tr>

        <tr>

            <td>

                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

            </td>

            <td>

                &nbsp;</td>

            <td class="style2">

                &nbsp;</td>

            <td>

                &nbsp;</td>

        </tr>

    </table>


     

        

        

        


    </script>


    thanks 

    Tuesday, December 28, 2010 5:24 AM

Answers

All replies

  • User616745175 posted

    do something like this...

    dbConnection = new OleDbConnection();

                    dbConnection.ConnectionString = strConnectionString;
                    dbConnection.Open();
                    dbCommand = new OleDbCommand();
                    dbCommand.Connection = dbConnection;
                    dbCommand.CommandType = CommandType.Text;
                    dbCommand.CommandText = "update [tbluserlogin] set userPwd='" stringnewpassword(str) "' where userId=" + userId + " ;
                    dbCommand.ExecuteNonQuery();

    refer these links:

    http://www.eggheadcafe.com/community/aspnet/2/10125680/change-password-authorization.aspx

    better you use membership (default login controls ) it is secured and easy

    http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.changepassword.aspx

    http://www.asp.net/moving-to-aspnet-20/tutorials/membership

    Tuesday, December 28, 2010 6:12 AM
  • User1908679259 posted

    i wrote this code is working with out any error but it does not change the password in the DB ???



    Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
           
           
            Dim myConnection As OleDbConnection
            Dim myCommand As OleDbCommand
            Dim strSQL As String
           
            
           
            
            
            strSQL = "UPDATE tblLoginInfo SET password = " & CDbl(TextBox1.TextMode) & " WHERE(username  = " & lblUsername.Text & ")"
            myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
              & "Data Source=" & Server.MapPath("login.mdb") & ";")
            
            
            myConnection.Open()
            
            
            myCommand = New OleDbCommand(strSQL, myConnection)
     
            
            
            myConnection.Close()
        End Sub

    Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

                 

            Dim myConnection As OleDbConnection

            Dim myCommand As OleDbCommand

            Dim strSQL As String

                          

            

            strSQL = "UPDATE tblLoginInfo SET password = " & CDbl(TextBox1.TextMode) & " WHERE(username  = " & lblUsername.Text & ")"

            myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _

              & "Data Source=" & Server.MapPath("login.mdb") & ";")

            

            

            myConnection.Open()

                   

            myCommand = New OleDbCommand(strSQL, myConnection)


                   

            myConnection.Close()

        End Sub


    Wednesday, December 29, 2010 3:15 AM
  • User-1199946673 posted

    Password is a Reserved Word in Access. This meand that you shoudl enclose it in brackets when used as a field (or table) name

     UPDATE tblLoginInfo SET [password] =

    And I don; t see a space after WHERE:

    WHERE(username

    should be

    WHERE (username

    Also, you better start using parameterized queries:

    http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access

    And make sure that you database cannot be downloaded directly, for example putting it in the App_Data folder:

    http://www.mikesdotnetting.com/Article/78/AccessDataSource-SqlDataSource-and-connecting-to-Access-databases-in-ASP.NET

    And it doesn't make much sence to me to change the passowrd into the TextMode value of your TextBox!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 29, 2010 4:02 AM