Click or drag to resize

VGSecurityManagerAuthenticationState Property

Gets a VGAuthenticationState object representing the last authentication state.

Namespace:  Novalys.VisualGuard.Security
Assembly:  Novalys.VisualGuard.Security (in Novalys.VisualGuard.Security.dll) Version: 2018.1.720.18 (2018.1.0720.18)
Syntax
public static VGAuthenticationState AuthenticationState { get; }

Property Value

Type: VGAuthenticationState
Remarks
You can use this value to test if the last authentication has failed or not and to check reason of the failure.
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 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();
        }
    }
}
See Also