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:
Private mdbLogin As Database Private Sub cmdOK_Click() Dim rstUsers As Recordset Dim newPassword As String If (Len(Trim(txtUserName.Text)) > 0) Then Set mdbLogin = OpenDatabase(App.Path & "\Login.mdb", False, False, ";pwd=AdmiN") Set rstUsers = mdbLogin.OpenRecordset("SELECT * FROM Users WHERE UserName='" & _ Trim(txtUserName.Text) & "'") Else ShowError "Please enter a user name" Exit Sub End If With rstUsers If (.RecordCount > 0) Then If (.Fields("Password").Value = txtPassword.Text) Then 'User has logged in LogEvent "User logged in: " & txtUserName If txtPassword = "changeme" Then Do 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.") If newPassword = "" Or newPassword = "changeme" Then MsgBox "The password cannot be 'changeme' or blank. Please enter a different password.", vbCritical Else 'Here's where I'm stuck, I have no idea what to do to update the data in the database Exit Do End If Loop End If Unload Me 'Allow user access to the computer Else LogEvent "Invalid password: " & txtUserName & ", " & txtPassword ShowError "The password you entered is invalid" txtPassword.SetFocus txtPassword.SelStart = 0 txtPassword.SelLength = Len(txtPassword.Text) End If Else LogEvent "Invalid username: " & txtUserName & ", " & txtPassword ShowError "The user name you entered is invalid" End If End With rstUsers.Close Set rstUsers = Nothing mdbLogin.Close Set mdbLogin = Nothing End Sub




Reply With Quote