I think this should be a quick question, and I hope this is a good place to ask it.
Edit: Maybe this will make the discussion, suggestions, and answers a bit more pointed: Given that I have a situation where I have no option but to pass a plain text password to an input element on an html web page, what is the most secure way I can handle that password also given that I am using a wpf password box to retrieve it from the user, I am using .SecurePassword
to retrieve the password from the password box, and using the function detailed below to pass that secure string to the input element and then immediately submitting the form to the server.
I have written a small WPF application that automates a process for our office. As part of that application, a user ID and password is passed to an outside vendor. This application remains open on the user's desktop so this process can be performed multiple times over the course of the day.
As I've written the application now, the password is entered by the user into a wpf password box once, and the password property is only accessed when the vendor site needs it. At no point to I pass the password to another property or text string variable.
My question has to do with the security of this approach. I'm not an IT security expert, and we don't honestly expect to have any issues with this due to the internal implementation of it, but I did want to see how the password box stores that password.
It is my understanding that in this scenario the only time the password lives in memory in plain text is at the moment it is passed from our application to the outside vendor's application, which is a risk that is more or less unavoidable. The outside vendor has not provided us with an API, so the best we can do is vendor site input element.value = passwordbox.password
Can someone highlight potential risks of this approach, maybe an alternative method if one exists, or arguments for it's security if those exist.
Again, this is a small app to be used internally by one department. We aren't anticipating issues, but we are expecting to field a few questions about it. I've reviewed the Microsoft documentation, but I wanted to see if perhaps someone with more experience might have something to add.
Thanks in advance for all your help!
EDIT: Still working on this but I've gotten some good feedback that I've taken into account. I've adapted the approach from the page that Mare Infinitus posted, http://blogs.msdn.com/b/fpintos/archive/2009/06/12/how-to-properly-convert-securestring-to-string.aspx
Here is what I have now:
The user enters their password into the WPF password box. I have the following function:
Private Function ConvertToUnsecureString(ByVal SecurePassword As SecureString) As String
If SecurePassword Is Nothing Then Throw New ArgumentNullException("SecurePassword")
Dim unmanagedString As IntPtr = IntPtr.Zero
Try
unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(SecurePassword)
Return Marshal.PtrToStringUni(unmanagedString)
Catch ex As Exception
Finally
Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString)
End Try
End Function
Using that function I'm passing the password to the input element like this:
InputEl.value = ConvertToUnsecureString(Me.PasswordBox.SecurePassword)
At the moment, that seems to be as good as it gets, but I'm still interested in further strategies / ideas that might be more secure.