Purpose: This document discusses how to authenticate users in a web environment using the StrataFrame security module.
Authenticating Users
Authenticating users within a web application is very similar to authenticating users within a Windows environment; however, no default login form or form template is provided for web applications. As such, authentication must be done programmatically using methods of the MicroFour.StrataFrame.Security.Login class.
Note: The reasoning behind the omission of a default login form or login form template is that each web-based login form is fundamentally different depending on requirements. Also most login forms are not just login forms, but frames or regions within more complex forms.
Login Methods Used within a Web Application
The AuthenticateUser() and SetLoggedInUser() methods of the Login class are typically used to authenticating users within a web application:
- AuthenticateUser() - The AuthenticateUser() method does not change the CurrentUser object, but returns a value containing the results of the authentication request.
- SetLoggedInUser() - The SetLoggedInUser() method returns a value containing the results of the authentication request. If the authentication is successful, it also changes the CurrentUser object to be the new user.
Imports MicroFour.StrataFrame.Security
...
Private Sub cmdLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handle cmdLogin.Click
'-- Establish locals
Dim loResult As Login.LoginResult
'-- Attempt to authenticate the user
loResult = Login.SetLoggedInUser(UserName, Password, "")
'-- If the result if Success, AdminLoggedOn, or SecMaintUserLoggedOn, the
' SecurityBasics.CurrentUser object will be changed to the correct user
'-- Do something based upon the result
Select Case loResult
Case Login.LoginResult.Success
Case Login.LoginResult.Failure
Case Login.LoginResult.UserDeactivated
...
End Select
End Subusing MicroFour.StrataFrame.Security;
...
private void cmdLogin_Click(object sender, EventArgs e)
{
//-- Establish locals
Login.LoginResult loResult;
//-- Attempt to authenticate the user
loResult = Login.SetLoggedInUser(UserName, Password, "");
//-- If the result if Success, AdminLoggedOn, or SecMaintUserLoggedOn, the
// SecurityBasics.CurrentUser object will be changed to the correct user
//-- Do something based upon the result
switch (loResult)
{
case Login.LoginResult.Success:
case Login.LoginResult.Failure:
case Login.LoginResult.UserDeactivated:
...
}
}