title: Secure windows Impersonation?
body: <p>In my WPF application I want to allow administrators to test a database connection using integrated security for various other users. So I have a form that allows the admin to enter the domain, username and password and then test it. I am able to securely handle the password right up until I call <code>LogonUser</code> in the <code>advapi32.dll</code> which takes a <code>string password</code></p>
  
  <pre><code>LogonUser(UserName, Domain, Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref UserHandle)
  </code></pre>
  
  <p>I have written a utility function which converts the SecureString to a string as safe as possible, and then im calling it on the password in the LogonUser call:</p>
  
  <pre><code>LogonUser(UserName, Domain, Helper.ConvertSafely(Password), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref UserHandle)
  </code></pre>
  
  <p>Since the signature for LogonUser takes a string, unless LogonUser is taking proper care of the password in its execution, it could still be on my call stack in plain text after the call returns.  Is there a more secure way to impersonate a user in which i can be confidant the PW is secure the whole time?</p>
  
  <p>Basically all I need is a <code>WindowsImpersonationContext</code> but i would like to aquire it without the password ever being in plain text.</p>