Question:
How can I log in to an application with a barcode?
Solution:
To do so, follow these procedures:
- First, make sure you have the device (barcode) set up and working properly;
- Then, use a database to create a table with at least three columns: login, password, and code;
- Create the same users from Studio;
- Create a query filtering per read code and returning the corresponding user;
- Retrieve these values (login and password) with GetADORecordSet() method, and send them to LoginUser() method. This will allow the user to log in directly, without having to type login and password. Alternatively, you can use PasswordConfirm(True) method.
The resulting script will be similar to this:
(replace “Text9.Value” with the tag related to the read code)
dim Username, UserPassword
set query = Screen.Item(“QueryF”)
query.SetVariableValue “CodeRead”, Screen.Item(“Text9”).Value
set filter = query.GetADORecordset()
if filter.RecordCount > 0 then
Username = filter.Fields(“Login”).Value
UserPassword = filter.Fields(“Password”).Value
Application.LoginUser Username, UserPassword
if Application.PasswordConfirm(True) = False then
MsgBox “Incorrect Password!”
End If
else
MsgBox “Error when reading code!”
End if
set query = Screen.Item(“QueryF”)
query.SetVariableValue “CodeRead”, Screen.Item(“Text9”).Value
set filter = query.GetADORecordset()
if filter.RecordCount > 0 then
Username = filter.Fields(“Login”).Value
UserPassword = filter.Fields(“Password”).Value
Application.LoginUser Username, UserPassword
if Application.PasswordConfirm(True) = False then
MsgBox “Incorrect Password!”
End If
else
MsgBox “Error when reading code!”
End if
The sample application attached to this article has been developed with E3 v3.1, build 285.