Purpose: This document describes the use of the Login class and its methods.
Login Class Methods
The MicroFour.StrataFrame.Security.Login class is a sealed, static class that contains shared (static) methods that are used to authenticate users against the security system. There are 4 main methods within the Login class that you will use most often:
- AuthenticateUser()
- SetLoggedInUser()
- ShowLoginAndAuthUser()
- ShowPasswordChangeForm()
AuthenticateUser()
The AuthenticateUser() method accepts a users credentials and returns a LoginResult of the authentication results. It does not change the SecurityBasics.CurrentUser object, but instead returns a new SFSUsersBO object through the ByRef (ref) UserInfo parameter containing the information on the current user if the user was successfully authenticated.
Imports MicroFour.StrataFrame.Security
Imports MicroFour.StrataFrame.Security.BusinessObjects
...
Private Sub AuthUser(ByVal UserName As String, ByVal Password As String)
'-- Establish locals
Dim loUserInfo As SFSUsersBO = Nothing
Dim loResult As Login.LoginResult
'-- Attempt to authenticate the user
loResult = Login.AuthenticateUser(UserName, Password, "", loUserInfo)
'-- 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;
using MicroFour.StrataFrame.Security.BusinessObjects;
...
private void AuthUser(string UserName, string Password)
{
//-- Establish locals
SFSUsersBO loUserInfo = null;
Login.LoginResult loResult;
//-- Attempt to authenticate the user
loResult = Login.AuthenticateUser(UserName, Password, "", ref loUserInfo);
//-- Do something based upon the result
switch (loResult)
{
case Login.LoginResult.Success:
case Login.LoginResult.Failure:
case Login.LoginResult.UserDeactivated:
...
}
}SetLoggedInUser()
The SetLoggedInUser() method accepts a user's credentials and returns a LoginResult of the authentication results. This method will also set the CurrentUser object to the appropriate LoggedInUser, AdminUser, or SecurityMaintenanceUser object if the user is successfully authenticated.
Imports MicroFour.StrataFrame.Security
...
Private Sub SetUser(ByVal UserName As String, ByVal Password As String)
'-- 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 SetUser(string UserName, string Password)
{
//-- 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:
...
}
}ShowLoginAndAuthUser()
The ShowLoginAndAuthUser() method is used to display the LoginForm currently set as the Login.LoginFormType to the end-user, gather the user's credentials, authenticate the user, and set the CurrentUser object to the appropriate user object. This method accepts a Boolean parameter that determines whether the end-user should be allowed to cancel out of the form to close the application. It is generally called from within the ShowLoginAndInitMainForm() method of the AppMain.vb (program.cs) file.
Private Shared Sub ShowLoginAndInitMainForm(ByVal e As ShowLoginAndInitFormEventArgs) '-- Set the login form to your custom login form (optional) Login.LoginFormType = GetType(MyCustomLoginForm) '-- Show the login form and authenticate the user e.ShowMainForm = Login.ShowLoginAndAuthUser(True) End Sub
private static void ShowLoginAndInitMainForm(ShowLoginAndInitFormEventArgs e)
{
//-- Set the login form to your custom login form (optional)
Login.LoginFormType = typeof(MyCustomLoginForm);
//-- Show the login form and authenticate the user
e.ShowMainForm = Login.ShowLoginAndAuthUser(true);
}ShowPasswordChangeForm()
The ShowPasswordChangeForm() method shows a password change dialog to the end-user to allow them to change their password. All security preferences are followed when the end-user attempts to set their password (password history, max length, min length, complexity, etc.). This method returns a Boolean value indicating whether the end-user's password was successfully changed or whether the user canceled out of the form.
Private Function ChangeUsersPassword() As Boolean
Return Login.ShowPasswordChangeForm()
End Functionprivate bool ChangeUsersPassword()
{
return Login.ShowPasswordChangeForm();
}