Tuto WEBDEV 25

60 Part 1: Discovering WEBDEV ▶ For the "CONNECT" Button control, we must write the WLanguage code to perform the search: 1. Select the "CONNECT" Button control and display the associated events (F2). 2. Write the following WLanguage code in the "Click (server)" event: HReadSeekFirst(Registration, Login, EDT_Login) IF NOT HFound(Registration) THEN Error("Unknown login.") ELSE IF EDT_Password = Registration.Password THEN Info("OK, you are connected.") ELSE Error("Incorrect password.") END END 3.  Let’s take a look at this WLanguage code: • This code is run in server code because a search is performed in the database that is located on the server. • HReadSeekFirst is used to find a value in a data file. The search is performed on the entire name by default. To perform a "Starts with" search, all you have to do is add a parameter: the hStartWith constant. • HFound is used to find out whether the search performed in the Registration data file was successful or not. The "IF NOT HFound" code is used to define the action to perform if the login is not found ("Login not found") as well as the action to perform if the login is found. • If the login is found, the password typed in the EDT_Password control is compared to the one found in the data file (for the specified login). If the two passwords are the same, then the user is connected, otherwise an error message is displayed. Remark The code presented here is for educational purpose. In a real project: • The password must not be stored in clear. We advise you to encrypt the password. • We advise you to display the same error message in case of incorrect login or password (to avoid an attempt to hack the logins). 4. Save (Ctrl + S) and close the code editor (cross in the top right corner).

RkJQdWJsaXNoZXIy NDQ0OA==