Authenticates a user by using the specified authentication mode.

Namespace: Novalys.VisualGuard.Security
Assembly: Novalys.VisualGuard.Security (in Novalys.VisualGuard.Security.dll) Version: 2016.0.105.16 (2016.0.105.16)

Syntax

C#
public static VGAuthenticationState Authenticate(
	string name,
	string password,
	VGAuthenticationMode mode
)
Visual Basic
Public Shared Function Authenticate ( 
	name As String,
	password As String,
	mode As VGAuthenticationMode
) As VGAuthenticationState

Parameters

name
Type: System..::..String
the name of the user.
password
Type: System..::..String
the password of the given user.
mode
Type: Novalys.VisualGuard.Security..::..VGAuthenticationMode
The mode of the authentication used to authenticate the user. If you indicates Windows, the user and password are ignored and Visual Guard will use the current windows account.

Return Value

Type: VGAuthenticationState
A VGAuthenticationState indicating if the authentication succeeds or not.

Examples

The following example displays how to test the state of the authentication
C# Copy imageCopy
Reauthenticate:
VGAuthenticationState state = VGSecurityManager.Authenticate(user.Text, password.Text);
if (state.IsFailed)
{
    if (state.IsCanceled) return;
    if (state.IsCredentialInvalid)
    {
        if (state.IsLastBadLogin)
        {
            MessageBox.Show("Invalid user or password. The next bad login will lock your account.");
        }
        else
        {
            MessageBox.Show("Invalid user or password");
        }
    }
    else if (state.IsUserNotAuthorized)
    {
        MessageBox.Show("user not authorized to log on the application");
    }
    else if (state.IsUserAccountExpired)
    {
        MessageBox.Show("your account is no more valid. Contact your administrator");
    }
    else if (state.IsUserAccountNotYetAvailable)
    {
        MessageBox.Show("your account is not yet available.");
    }
    else if (state.IsUserAccountLockedOut)
    {
        MessageBox.Show("your account is locked out. Contact your administrator.");
    }
    else if (state.MustChangePasswordAtNextLogon)
    {
        if (!state.IsPasswordSecure)
        {
            if (state.PasswordExpired)
            {
                MessageBox.Show("Your password has expired. You are required to change it.");
            }
            else
            {
            MessageBox.Show("Your password is not secure enough. You are required to change it.");
            }
        }
        else
        {
            MessageBox.Show("You are required to change your password at first logon.");
        }
        VGChangePasswordForm form = new VGChangePasswordForm(runtime);
        form.UserName = currentUsername;
        form.OldPassword = currentPassword;
        if (form.ShowDialog(this) == DialogResult.OK)
        {
            currentPassword = form.NewPassword;
            goto Reauthenticate;
        }
    }
}
else
{
    this.DialogResult = DialogResult.OK;
    if (!state.IsPasswordSecured)
    {
        if (MessageBox.Show("Your password is not secure enough or has expired. " + Environment.NewLine + "Do you want to change it?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) = DialogResult.Yes)
        {
            // Use the Visual guard form to change the password
            // You can replace it by your own form
            VGChangePasswordForm form = new VGChangePasswordForm();
            form.ShowDialog();
        }
    }
}
Visual Basic Copy imageCopy
Reauthenticate:
Dim state As VGAuthenticationState = VGSecurityManager.Authenticate(userTextBox.Text, passwordTextBox.Text)
If state.IsFailed Then
    Me.DialogResult = DialogResult.None
    If state.IsCanceled Then Return
    If state.IsCredentialInvalid Then
        If state.IsLastBadLogin Then
            MessageBox.Show("Invalid user or password. The next bad login will lock your account.")
        Else
            MessageBox.Show("Invalid user or password")
        End If
    ElseIf state.IsUserNotAuthorized Then
        MessageBox.Show("user not authorized to log on to the application")
    ElseIf state.IsUserAccountExpired Then
        MessageBox.Show("your account is no more valid. Contact your administrator")
    ElseIf state.IsUserAccountNotYetAvailable Then
        MessageBox.Show("your account is not yet available.")
    ElseIf state.MustChangePasswordAtNextLogon Then
        If Not state.IsPasswordSecure Then
            If state.IsPasswordExpired Then
                MessageBox.Show("Your password has expired. You are required to change it.")
            Else
                MessageBox.Show("Your password is not secure enough. You are required to change it.")
            End If
        Else
            MessageBox.Show("You are required to change your password at first logon.")
        End If
        Dim form As VGChangePasswordForm = New VGChangePasswordForm
        form.UserName = userTextBox.Text
        form.OldPassword = passwordTextBox.Text
        If form.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            passwordTextBox.Text = form.NewPassword
            GoTo Reauthenticate
        End If
    ElseIf state.IsUserAccountLockedOut Then
        MessageBox.Show("your account is locked out. Contact your administrator.")
    End If
Else
    Me.DialogResult = DialogResult.OK
    If Not state.IsPasswordSecured Then
        If MessageBox.Show("Your password is not secure enough or has expired. " + _
            Environment.NewLine + "Do you want to change it?", "", _
            MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
            MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) = DialogResult.Yes Then
            ' Use the Visual guard form to change the password
            ' You can replace it by your own form
            Dim form As VGChangePasswordForm = New VGChangePasswordForm
            form.ShowDialog()
        End If
    End If
End If

Exceptions

ExceptionCondition
System..::..ArgumentExceptionThe value of mode is equal to None or is a combination of several modes.

- or-

the name is an empty string or is longer than 64 characters.

- or-

the password is longer than 64 characters.
System..::..ArgumentNullException The name or the password is null (Nothing in VB) and the mode is not Windows.

See Also