Click or drag to resize

VGSecurityManagerAuthenticate Method (String, String)

Authenticates a user by using the database or Visual Guard authentication mode.

Namespace:  Novalys.VisualGuard.Security
Assembly:  Novalys.VisualGuard.Security (in Novalys.VisualGuard.Security.dll) Version: 2019.1.831.19 (2019.1.0831.19)
Syntax
public static VGAuthenticationState Authenticate(
	string name,
	string password
)

Parameters

name
Type: SystemString
the name of the user.
password
Type: SystemString
the password of the given user.

Return Value

Type: VGAuthenticationState
A VGAuthenticationState indicating if the authentication succeeds or not.
Exceptions
ExceptionCondition
ArgumentException the name is an empty string or is longer than 64 characters.

- or-

the password is longer than 64 characters.
ArgumentNullException The name or the password is null (Nothing in VB).
NotSupportedException

the repository does not support Visual Guard or database authentication mode.

Remarks
This method will use database authentication mode if this mode is allowed by the repository. If the authentication fails, it will try to authenticate by using the Visual Guard authentication mode.
Examples
The following example displays how to test the state of the authentication
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. " + 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();
        }
    }
}
See Also