Frage

I have a table contains usernames and passwords and i want to create login panel with two textboxes(username and password). How can i check the values in textbox with the all users and passwords?

War es hilfreich?

Lösung

In VBA you can test:

Dim count As Long

count = DCount("*", "tblUser", "UserName='" & Replace(Me!txtUser,"'","''") & _
    "' AND Password='" & Replace(Me!txtPwd, "'", "''") & "'")
If count > 0 Then
    'User exists and password is correct.
Else
    'Either the user or the password or both are wrong.
End If

The replace functions make sure that single quotes (') that are part of the user input are escaped correctly. In SQL single quotes are used to delimit strings and a quote within the text can be escaped with two consequtive quotes.

As an example, the where condition could be:

UserName='Joe''s friend' AND Password='secret'
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top