It is very easy to change the old password, all you need to do is rewrite that particular file with the new one. Also tell the user to type the old password so that the right user is changing the password without any conflicts. After that create a new function which will write a password to the txt file and if any new user is using it then just call it and if that user is not using it then simply ask for old password and check if its a correct call for the same function made or not. You have to then use "&" for the code you may use when adding strings together instead of using "+". Check the below code which will show you how the compiler will try to sum up the strings:
Code:
Option Explicit
'user info(password and username)'
Private Type USER_INFO
UserName As String
Password As String
End Type
Private UI As USER_INFO
Private Function Write_UsreInfo_In_File() As String
'function that write the user info to a file'
'the function return "SUCCSESS" if the file is writen correct'
'and return the error number and discription in case of error'
On Error GoTo err_h
'open the file for input'
Open App.Path & "\Users\" & openfile & ".txt" For For Binary As #2
'write in the file the whole structure'
Put #2, , UI
'close the file'
Close 2
'return result'
Write_UsreInfo_In_File = "SUCCSESS"
Exit Function
err_h:
Write_UsreInfo_In_File = Err.Number & " " & Err.Description
End Function
Private Sub cmdChangePass_Click()
'check for username if the textbox is empty exit the sub'
If txtUsername.Text = "" Then
MsgBox "ENTER USER NAME", vbCritical
Exit Sub
End If
'check password if textbox is empty exit sub'
If txtPassword.Text = "" Then
MsgBox "ENTER PASSWORD", vbCritical
Exit Sub
End If
'check for the new password'
If txtNewPassword.Text = "" Then
MsgBox "ENTER NEW PASSWORD", vbCritical
Exit Sub
End If
'load the user info'
Load_User_Info
'check for the password and username'
If txtPassword.Text = UI.Password And txtUsername.Text = UI.UserName Then
'if they are correct add the info to the type'
UI.Password = txtNewPassword.Text
UI.UserName = txtUsername.Text
'save the info to the file'
MsgBox Write_UsreInfo_In_File
Else
'if not a mesage show up'
MsgBox "INVALID USERNAME OR PASSWORD!!!", vbInformation
End If
End Sub
Private Sub cmdNewUser_Click()
'check for username if the textbox is empty exit the sub'
If txtUsername.Text = "" Then
MsgBox "ENTER USER NAME", vbCritical
Exit Sub
End If
'check for password if the textbox is empty exit the sub'
If txtPassword.Text = "" Then
MsgBox "ENTER PASSWORD", vbCritical
Exit Sub
End If
'input the info for the new user in the type and show the msg from the function'
UI.Password = Text2.Text
UI.UserName = Text1.Text
MsgBox Write_UsreInfo_In_File
End Sub
Private Sub Load_User_Info()
'the sub load the user info from a file to the type'
Open App.Path & "\Users\" & openfile & ".txt" For Binary As #2
Get #2, , UI
Close 2
End Sub
Bookmarks