Results 1 to 2 of 2

Thread: Easy - Modifying database data - RESOLVED

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187

    Resolved Easy - Modifying database data - RESOLVED

    OK... I knew nothing about databases this morning... And I still really don't. The idea here is to create a security system with multiple user names and passwords. I would like to start out all users with the password "changeme," and after the first login, it will change their password. I found code below on Planet Source code and modified it to suit my needs; all except for writing the password back to the Access database.

    I know this must be really simple... but I've never messed with databases before; I don't know anything about them.

    VB Code:
    1. Private mdbLogin As Database
    2.  
    3. Private Sub cmdOK_Click()
    4.  
    5.     Dim rstUsers As Recordset
    6.     Dim newPassword As String
    7.    
    8.     If (Len(Trim(txtUserName.Text)) > 0) Then
    9.         Set mdbLogin = OpenDatabase(App.Path & "\Login.mdb", False, False, ";pwd=AdmiN")
    10.         Set rstUsers = mdbLogin.OpenRecordset("SELECT * FROM Users WHERE UserName='" & _
    11.             Trim(txtUserName.Text) & "'")
    12.     Else
    13.         ShowError "Please enter a user name"
    14.         Exit Sub
    15.     End If
    16.    
    17.     With rstUsers
    18.         If (.RecordCount > 0) Then
    19.             If (.Fields("Password").Value = txtPassword.Text) Then
    20.                    
    21.                     'User has logged in
    22.                    
    23.                     LogEvent "User logged in: " & txtUserName
    24.                    
    25.                     If txtPassword = "changeme" Then
    26.                    
    27.                     Do
    28.                    
    29.                         newPassword = InputBox("This appears to be the first time you have logged in. Please enter a new password for your account. You are responsible for all activity which occurs on the computer while you are logged in.")
    30.                    
    31.                         If newPassword = "" Or newPassword = "changeme" Then
    32.                             MsgBox "The password cannot be 'changeme' or blank. Please enter a different password.", vbCritical
    33.                         Else
    34.                             'Here's where I'm stuck, I have no idea what to do to update the data in the database
    35.                             Exit Do
    36.                         End If
    37.                    
    38.                     Loop
    39.                    
    40.                     End If
    41.                    
    42.                     Unload Me 'Allow user access to the computer
    43.                
    44.             Else
    45.                 LogEvent "Invalid password: " & txtUserName & ", " & txtPassword
    46.                 ShowError "The password you entered is invalid"
    47.                 txtPassword.SetFocus
    48.                 txtPassword.SelStart = 0
    49.                 txtPassword.SelLength = Len(txtPassword.Text)
    50.             End If
    51.         Else
    52.             LogEvent "Invalid username: " & txtUserName & ", " & txtPassword
    53.             ShowError "The user name you entered is invalid"
    54.         End If
    55.     End With
    56.    
    57.     rstUsers.Close
    58.     Set rstUsers = Nothing
    59.  
    60.     mdbLogin.Close
    61.     Set mdbLogin = Nothing
    62. End Sub
    Last edited by Allen Schoessler; Jan 22nd, 2005 at 07:03 PM.
    - Visual Basic 6.0
    - Windows XP Home

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187

    Re: Easy - Modifying database data

    Got it...

    .Edit
    !Password = newPassword
    .Update

    ... is what I was looking for!
    - Visual Basic 6.0
    - Windows XP Home

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width