none
"\nError: [1326] Logon failure: unknown user name or bad password.\r\n" string

    Question

  • Hi,

    I am getting error at below method. this method is calling in upload method.

    public static object m_ImpersonateWithDelegate(string domainName, string userName, string passWord,
    ImpersonationObject impDelegate, int logonType)
    {
    LogonType = logonType;
    object retObject = null;

    IntPtr tokenHandle = new IntPtr(0);
    IntPtr dupeTokenHandle = new IntPtr(0);

    // Get the user token for the specified user, domain, and password using the 
    // unmanaged LogonUser method. 
    // The local machine name can be used for the domain name to impersonate a user on this machine.

    //This parameter causes LogonUser to create a primary token.
    const int SecurityImpersonationLevel = 2;

    tokenHandle = IntPtr.Zero;
    dupeTokenHandle = IntPtr.Zero;

    // Call LogonUser to obtain a handle to an access token.
    //bool returnValue = LogonUser(userName, domainName, passWord, logonType, Logon32.ProviderDefault, ref tokenHandle);
    bool returnValue = LogonUser(userName, domainName, passWord, logonType, Logon32.ProviderDefault, ref tokenHandle);

    Debug.WriteLine("LogonUser called.");

    if (false == returnValue)
    {
    int ret = Marshal.GetLastWin32Error();
    Debug.WriteLine("LogonUser failed with error code : " + ret.ToString());
    string msg = String.Concat("\nError: [", ret.ToString(), "] ", GetErrorMessage(ret));
    Debug.WriteLine(msg);
    int errorCode = 0x5; //ERROR_ACCESS_DENIED
    throw new System.ComponentModel.Win32Exception(errorCode);
    }

    Debug.WriteLine("Did LogonUser Succeed? " + (returnValue ? "Yes" : "No"));
    Debug.WriteLine("Value of Windows NT token: " + tokenHandle);

    // Check the identity.
    Debug.WriteLine("Before impersonation: " + WindowsIdentity.GetCurrent().Name);

    bool retVal = DuplicateToken(tokenHandle, SecurityImpersonationLevel, ref dupeTokenHandle);
    if (false == retVal)
    {
    CloseHandle(tokenHandle);
    Debug.WriteLine("Exception thrown in trying to duplicate token.");
    return retObject;
    }

    Thursday, September 12, 2013 11:47 AM

Answers

  • The error is saying the UN/PWD isn't valid and therefore you cannot impersonate the user.  Verify the info you're passing it.  I'm assuming the \r\n stuff is just a copy/paste issue on you're part.  If it is actually part of the error message then ensure that your UN/PWD doesn't include them.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Thursday, September 12, 2013 2:00 PM
    Moderator