By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,226 Members | 1,435 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,226 IT Pros & Developers. It's quick & easy.

Code to update New Password in Place of old password in Employee Table

P: 2
I have created a table called EmployeeTable and am done with login page, But problem is, when ever a user try to change password it shows "password change sucessfull" but the new password not been updated(replaced) in place of old password in employee table. so am attaching the code which i have written in VB(Ms access 2003). pls give me a code to update password.. (For Esay understanding I have provided the space where i need to update my codes in program (before Mess box "password change sucessful"))
Expand|Select|Wrap|Line Numbers
  1. Private Sub SaveExit_Click()
  3. 'Check to see if data is entered into the Employee ID box
  5.     If IsNull(Me.EmployeeID) Or Me.EmployeeID = "" Then
  6.         MsgBox "You must enter a Employee ID.", vbOKOnly, "Required Data"
  7.         Me.EmployeeID.SetFocus
  8.         Exit Sub
  9.     End If
  11. 'Check to see if data is entered into the old password box
  13.     If IsNull(Me.oldpassword) Or Me.oldpassword = "" Then
  14.         MsgBox "You must enter a Old Password.", vbOKOnly, "Required Data"
  15.         Me.oldpassword.SetFocus
  16.         Exit Sub
  17.     End If
  19. 'Check to see if data is entered into the New password box
  21.     If IsNull(Me.newpassword) Or Me.newpassword = "" Then
  22.         MsgBox "You must enter a New Password.", vbOKOnly, "Required Data"
  23.         Me.newpassword.SetFocus
  24.         Exit Sub
  25.     End If
  26. 'Check to see if data is entered into the New password box
  28.     If IsNull(Me.confirmpassword) Or Me.confirmpassword = "" Then
  29.         MsgBox "Please Confirm Password.", vbOKOnly, "Required Data"
  30.         Me.newpassword.SetFocus
  31.         Exit Sub
  32.     End If
  33. 'check to see the Password in EmployeeTable
  35.     If Me.oldpassword.Value = DLookup("Password", "EmployeeTable", "[EmployeeID]=" & Me.EmployeeID.Value) Then
  37.         EmployeeID = Me.EmployeeID.Value
  39.     Else
  40.         MsgBox "Old Password Not Matched . Please Try Again", vbOKOnly, "Invalid Entry!"
  41.         Me.oldpassword.SetFocus
  42.         Exit Sub
  43.     End If
  44. 'check to see the New Password should match with confirm Password
  45.     If Me.newpassword.Value = Me.confirmpassword.Value Then
  46. 'Replace Password In Employee Table by New passsword
  56.         MsgBox "Password Change Sucessfull", vbOKOnly, "Invalid Entry!"
  57. 'Close Change Password  form and open LogIN screen
  58.         DoCmd.Close acForm, "changepassword", acSaveNo
  59.         DoCmd.OpenForm "LogIN"
  60.     Else
  61.         MsgBox "New Password Not Matched . Please Try Again", vbOKOnly, "Invalid Entry!"
  62. End If
  63. End Sub
Jan 11 '12 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 10K+
P: 12,421
The problem is that you don't actually have any code to change the password, that's why the password stays the same in the table.
Jan 11 '12 #2

P: 2
ya that i know, thats why i given space there.. if u have the standard format of code, u post it..........
Jan 11 '12 #3

P: 759
Just this morning I write this code that seems to be what you are looking for. Of course you must operate some adaptations.

_Firme is a table (can be your table with passwords):
It has this fields:
- ID_Firma (Autonumber - Long): can be the ID field in your table
- FirmaName (Text - unique values): can be the field with names in your table
- IsDefault (Yes / No) : can be the field with passwords in your table

Also, in my form I have a combo box bound to this table with two columns: first two fields.
When I select a name from my combo box the value for combo box become equal to record ID

Then I use this code to set the IsDefault field to True for that record and for all other records to False (you can use that to store your new password)

Expand|Select|Wrap|Line Numbers
  1. Dim DB As DAO.Database
  2.     Set DB = CurrentDb()
  3. Dim Rst As DAO.Recordset
  4.     Set Rst = DB.OpenRecordset("_Firme")
  5.     Rst.MoveFirst
  6.     Do While Not Rst.EOF()
  7.         With Rst
  8.             .Edit
  9.             !IsDefault = (CLng(cmbFirma) = Rst!ID_Firma)
  10.             .Update
  11.             .MoveNext
  12.         End With
  13.     Loop
  14.     Rst.Close
  15.     Set Rst = Nothing

Pay attention to .Edit and .Update statements:
If first is ommited an error occur (Believe me !!! :))) ).
If the second one is omitted nothing happen in the table (again Believe me !!! :))) )

Hope this is a help for you.
Good luck !
Jan 11 '12 #4

Expert Mod 15k+
P: 31,707
Please check out When Posting (VBA or SQL) Code, as well as the site guidelines it seems you need to read too.
Jan 11 '12 #5

Expert Mod 10K+
P: 12,421
You don't necessarily have to use the record set based approach that Mihail uses. You can use something as simple as the DoCmd.RunSQL() function to execute an update query.

One related caveat to password storage. I notice you're storing the password as plain text. I just want to say that that is highly insecure and borders on reckless. If you're going to be storing passwords, you really need to store the hash, preferably with a salt. Storing plaintext passwords is how accounts get compromised, and not just the account for the program you have but a lot of people use the same password for everything and it compromises all those accounts too.
Jan 11 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.