You may not want to store the password in clear text in memory, from the msdn doc you should use SecurePassword in order to prevent that.
Example: SecureString myPass = passwordBox.SecurePassword
https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.passwordbox.securepassword