Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how update password for a user in access using c#

how update password for a user in access using c#

Scheduled Pinned Locked Moved C#
csharpsecurityannouncement
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User3490
    wrote on last edited by
    #1

    I have 3 textboxes (txtoldpassword,txtnewpassword,txtconfirmpassword) and i want to take the data that dives a user and if a user password exists in access then i can update the user password. i try this but it doesn't work. private void btnSave_Click(object sender, EventArgs e) { if (txtOldPassword.Text.Length == 0 || txtNewPassword.Text.Length == 0 || txtConfPassword.Text.Length == 0) { MessageBox.Show("Please Fill all the fields."); } else if (txtNewPassword.Text != txtConfPassword.Text ) { MessageBox.Show(" Please insert again your new password."); } else { OleDbConnection connect = new OleDbConnection(); connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Desktop\Laiki_Trapeza_Questionnaires.accdb;Persist Security Info=False;"; connect.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connect; command.CommandText = (@"UPDATE Users_Table SET Password= '" + txtNewPassword.Text.ToString() + "' WHERE (Password='"+txtOldPassword.Text + "')"); MessageBox.Show(" Succesfull update password!"); connect.Close(); } }

    J OriginalGriffO P 3 Replies Last reply
    0
    • U User3490

      I have 3 textboxes (txtoldpassword,txtnewpassword,txtconfirmpassword) and i want to take the data that dives a user and if a user password exists in access then i can update the user password. i try this but it doesn't work. private void btnSave_Click(object sender, EventArgs e) { if (txtOldPassword.Text.Length == 0 || txtNewPassword.Text.Length == 0 || txtConfPassword.Text.Length == 0) { MessageBox.Show("Please Fill all the fields."); } else if (txtNewPassword.Text != txtConfPassword.Text ) { MessageBox.Show(" Please insert again your new password."); } else { OleDbConnection connect = new OleDbConnection(); connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Desktop\Laiki_Trapeza_Questionnaires.accdb;Persist Security Info=False;"; connect.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connect; command.CommandText = (@"UPDATE Users_Table SET Password= '" + txtNewPassword.Text.ToString() + "' WHERE (Password='"+txtOldPassword.Text + "')"); MessageBox.Show(" Succesfull update password!"); connect.Close(); } }

      J Offline
      J Offline
      Jibesh
      wrote on last edited by
      #2

      You haven't really executed the query yet. call command.ExecuteNonQuery()[^] right after

      command.CommantText

      i.e

      OleDbCommand command = new OleDbCommand();
      command.Connection = connect;
      command.CommandText = (@"UPDATE Users_Table SET Password= '" + txtNewPassword.Text.ToString() + "' WHERE (Password='"+txtOldPassword.Text + "')");
      int rowsAffected = command.ExecuteNonQuery();
      MessageBox.Show(" Succesfull update password!");

      Guidelines for posting questions in the forum Jibesh V P

      1 Reply Last reply
      0
      • U User3490

        I have 3 textboxes (txtoldpassword,txtnewpassword,txtconfirmpassword) and i want to take the data that dives a user and if a user password exists in access then i can update the user password. i try this but it doesn't work. private void btnSave_Click(object sender, EventArgs e) { if (txtOldPassword.Text.Length == 0 || txtNewPassword.Text.Length == 0 || txtConfPassword.Text.Length == 0) { MessageBox.Show("Please Fill all the fields."); } else if (txtNewPassword.Text != txtConfPassword.Text ) { MessageBox.Show(" Please insert again your new password."); } else { OleDbConnection connect = new OleDbConnection(); connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Desktop\Laiki_Trapeza_Questionnaires.accdb;Persist Security Info=False;"; connect.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connect; command.CommandText = (@"UPDATE Users_Table SET Password= '" + txtNewPassword.Text.ToString() + "' WHERE (Password='"+txtOldPassword.Text + "')"); MessageBox.Show(" Succesfull update password!"); connect.Close(); } }

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        To add to what jibesh said - please don't do it like that! Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

        If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        U 1 Reply Last reply
        0
        • U User3490

          I have 3 textboxes (txtoldpassword,txtnewpassword,txtconfirmpassword) and i want to take the data that dives a user and if a user password exists in access then i can update the user password. i try this but it doesn't work. private void btnSave_Click(object sender, EventArgs e) { if (txtOldPassword.Text.Length == 0 || txtNewPassword.Text.Length == 0 || txtConfPassword.Text.Length == 0) { MessageBox.Show("Please Fill all the fields."); } else if (txtNewPassword.Text != txtConfPassword.Text ) { MessageBox.Show(" Please insert again your new password."); } else { OleDbConnection connect = new OleDbConnection(); connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Desktop\Laiki_Trapeza_Questionnaires.accdb;Persist Security Info=False;"; connect.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connect; command.CommandText = (@"UPDATE Users_Table SET Password= '" + txtNewPassword.Text.ToString() + "' WHERE (Password='"+txtOldPassword.Text + "')"); MessageBox.Show(" Succesfull update password!"); connect.Close(); } }

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          And always use parameterized queries. And don't put the data access code in the even handler -- write a Data Access Layer. And what if multiple users have the same password? Plus your app will be "more professional" if the state of btnSave.Enabled is controlled by the TextBoxes.

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            To add to what jibesh said - please don't do it like that! Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

            If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

            U Offline
            U Offline
            User3490
            wrote on last edited by
            #5

            i cant understant where and how i must use this code at Password Storage: How to do it.[

            OriginalGriffO 1 Reply Last reply
            0
            • U User3490

              i cant understant where and how i must use this code at Password Storage: How to do it.[

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              Any particular part you don't understand?

              If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              U 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                Any particular part you don't understand?

                If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

                U Offline
                U Offline
                User3490
                wrote on last edited by
                #7

                I try to put the code for password cryptography in my btnSave button so that when i press this button the user password will save to the access database with cryptography view but i believe that the functions MatchSHA1, GetSHA1 and RunTest must be out from the function btnSave but i can understand the parameters that must use to call these functions. What are p1 and p2? private void btnSave_Click(object sender, EventArgs e) { if (txtOldPassword.Text.Length == 0 || txtNewPassword.Text.Length == 0 || txtConfPassword.Text.Length == 0) { MessageBox.Show("Please Fill all the fields."); } else if (txtNewPassword.Text != txtConfPassword.Text ) { MessageBox.Show(" Please insert again your new password."); } else { OleDbConnection connect = new OleDbConnection(); connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Desktop\Laiki_Trapeza_Questionnaires.accdb;Persist Security Info=False;"; connect.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connect; private static bool MatchSHA1(byte[] p1, byte[] p2) { bool result = false; if (p1 != null && p2 != null) { if (p1.Length == p2.Length) { result = true; for (int i = 0; i < p1.Length; i++) { if (p1[i] != p2[i]) { result = false; break; } } } } return result; } /// /// Returns the SHA1 hash of the combined userID and password. /// /// /// /// private static byte[] GetSHA1(string userID, string password) { SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider(); return sha.ComputeHash(System.Text.Encoding.ASCII.GetBytes(userID + password)); } private static void RunTest()

                OriginalGriffO 1 Reply Last reply
                0
                • U User3490

                  I try to put the code for password cryptography in my btnSave button so that when i press this button the user password will save to the access database with cryptography view but i believe that the functions MatchSHA1, GetSHA1 and RunTest must be out from the function btnSave but i can understand the parameters that must use to call these functions. What are p1 and p2? private void btnSave_Click(object sender, EventArgs e) { if (txtOldPassword.Text.Length == 0 || txtNewPassword.Text.Length == 0 || txtConfPassword.Text.Length == 0) { MessageBox.Show("Please Fill all the fields."); } else if (txtNewPassword.Text != txtConfPassword.Text ) { MessageBox.Show(" Please insert again your new password."); } else { OleDbConnection connect = new OleDbConnection(); connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Desktop\Laiki_Trapeza_Questionnaires.accdb;Persist Security Info=False;"; connect.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connect; private static bool MatchSHA1(byte[] p1, byte[] p2) { bool result = false; if (p1 != null && p2 != null) { if (p1.Length == p2.Length) { result = true; for (int i = 0; i < p1.Length; i++) { if (p1[i] != p2[i]) { result = false; break; } } } } return result; } /// /// Returns the SHA1 hash of the combined userID and password. /// /// /// /// private static byte[] GetSHA1(string userID, string password) { SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider(); return sha.ComputeHash(System.Text.Encoding.ASCII.GetBytes(userID + password)); } private static void RunTest()

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  No, Run test is just an example of how to use the other two methods...

                  If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups