Show("Invalid username or password.", this.Text);
}
}
else
{
MessageBox.Show("Enter a valid username and password.", this.Text);
}
Below the Click() event of the OK button, add the following code. This code is what the Click() event
will call to authenticate the user entered on the login form.
private bool Authenticate(string un, string pwd)
{
bool isValid = false;
FabrikamDataContext context = new FabrikamDataContext("user id=username;
password=password");
IEnumerable
result = context.GetActiveEmployees();
foreach (GetActiveEmployeesResult emp in result)
{
if (emp.LoginName.ToLower() == un.ToLower() && emp.Password == pwd)
{
isValid = true;
break;
}
}
return isValid;
}
Before proceeding, compile the application to make sure that everything compiles OK. If there are no
errors, press F5 to run the application. First, the login form will appear. For credentials, enter RussellK
for the username and password for the password.
The Authenticate routine uses LINQ to SQL to call a mapped stored procedure to return all the existing
employees.
Pages:
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497