Database Storage with the ASP.NET Web Matrix: Simple Login Page - Switch to the Code view
(Page 3 of 5 )
Switch to the Code view in the Web Matrix and drag a SELECT function onto the page to launch the Select Code Wizard dialog box. Make sure the members database is selected and click the Next button. In the Columns panel of the next window, check the Username tick box, then click the Where button. The Where Clause Builder will already be set correctly, so just click Ok. Click the Next button twice and then set a name for the function, such as checkUserName, make sure the DataSet radio is selected, and click Finish. This will add the first of our SELECT functions to the page.
To create the second SELECT function, drag another SELECT onto the page; this time, choose both the Username the Password tick boxes and in the Where Clause Builder dialog, select Username in the Left Operand Column panel and click Ok. Now click the And Clause button and this time, choose Password as the Left Operand and click Ok. Click the Next button twice and then set the function name to checkUserPass. Again, ensure the DataSet radio is selected.
The following screenshot shows the vast amount of code that the Wen Matrix has just written for you:

To call these functions and check the user’s information, go back to the Design view in the Web Matrix, and double-click the Submit button. This will add a click event to the Code view. Go back to the Code view, and in the Sub add the following code:
lblUsernameError.Text = ""
lblPasswordError.Text = ""
lblWelcome.Text = ""
These three lines of code simply reset the messages when the Submit button is clicked so that, if a user enters an incorrect name on the first attempt, whichever error message is displayed gets switched off the next time the submit button is clicked. Otherwise, if a user submits an incorrect username or password before submitting a correct username and password, the error message will be displayed with the welcome message.
Next: Encrypting the password >>
More Database Articles
More By Dan Wellman