Results 1 to 3 of 3

Thread: How to Code a change password form in vb6

  1. #1
    Join Date
    May 2012
    Posts
    96

    How to Code a change password form in vb6

    I am unable to code a change password form using vb6, have tried many things but nothing is working. I want that the change password form should be accessed by a button on the login form (frmPassword) which is actually a seperate form to the login form (frmChangePassword). But from the login form, the change password form wont be reading the password even though after declaring password variable as the global variable. So can anyone help me out in this situation?

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: How to Code a change password form in vb6

    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

  3. #3
    Join Date
    May 2009
    Posts
    543

    Re: How to Code a change password form in vb6

    You can use the NewPassword method to change the database password, below are some of the examples mentioned to change password of the MyDB.mdb database to "MyPassword2" from "MyPassword1":

    Code:
       Sub ChangeDBPassword ()
          Dim Db As Database
    
          Set Db = OpenDatabase("C:\My Documents\MyDB.mdb",True, _
             False,";pwd=MyPassword1")
          Db.NewPassword "MyPassword1","MyPassword2"
          Db.Close
       End Sub
    If a wrong password is used then the above code will not handle the possibility of trying to open the database and it will just output an error. Every application that tries to open password protected databases should be able to handle this scenario.

Similar Threads

  1. old password usable after a password change
    By ADAMEE in forum Active Directory
    Replies: 1
    Last Post: 22-05-2011, 06:05 AM
  2. Need Password Reset Disk to change password for Windows 7
    By Alfanumeric in forum Operating Systems
    Replies: 3
    Last Post: 11-01-2011, 04:06 PM
  3. Access vba code form issue
    By Jaiwanti in forum Software Development
    Replies: 3
    Last Post: 06-07-2009, 12:32 PM
  4. Change password for users with blank password: Error
    By Ihit in forum Active Directory
    Replies: 3
    Last Post: 06-06-2008, 06:21 PM
  5. Change password/disable account - password cached?
    By gbug in forum Active Directory
    Replies: 3
    Last Post: 25-04-2008, 05:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,267,794.69726 seconds with 17 queries