Opc.Ua.UserIdentity.VerifyPassword C# (CSharp) Method

VerifyPassword() public static method

Verifies that the security token is a valid windows user.
public static VerifyPassword ( System.IdentityModel.Tokens.UserNameSecurityToken identityToken ) : void
identityToken System.IdentityModel.Tokens.UserNameSecurityToken The security token.
return void
        public static void VerifyPassword(UserNameSecurityToken identityToken)
        {
            if (identityToken == null)
            {
                throw ServiceResultException.Create(StatusCodes.BadIdentityTokenRejected, "Secuirty token is not a valid username token.");
            }

            // extract the username and domain from the security token.
            string username = identityToken.UserName;
            string domain = null;

            int index = username.IndexOf('\\');

            if (index != -1)
            {
                domain = username.Substring(0, index);
                username = username.Substring(index + 1);
            }

            IntPtr handle = IntPtr.Zero;

            int result = Win32.LogonUserW(
                username,
                domain,
                identityToken.Password, 
                Win32.LOGON32_LOGON_NETWORK,
                Win32.LOGON32_PROVIDER_DEFAULT,
                ref handle);

            if (result == 0)
            {
                throw ServiceResultException.Create(StatusCodes.BadIdentityTokenRejected, "Login failed for user: {0}", username);
            }

            Win32.CloseHandle(handle);
        }