Microsoft Virtualization Discussions

Data ONTAP Proxy SecureString issue?

rbarker

So why is this C# code throwing Incorrect credentials when the same code logs me in via PowerShell.

PowerShell login using ConvertTo-SecureString:

Thanks,

Rob

1 ACCEPTED SOLUTION

rbarker

Answered my own question but definitely with a head scratch. Modified code below; the only difference in the code is that I am reading the 3 parameters (controller IP/name, login and password) into string variables then using the resulting stored strings in my calls and everything works no problem.

       Proxy ontap = new Proxy();

            string IP = textBox1.Text.ToString();

            string login = textBox2.Text.ToString();

            string password = textBox3.Text.ToString();

            SecureString secpwd = new SecureString();

            foreach (char c in password)

       {

            secpwd.AppendChar(c);

       }

            PSCredential Credential = new PSCredential(login, secpwd);

           

       try

       {

                var controller = ontap.NaController.Connect(IP, null, Credential, commandSwitches:

                    NaController.ConnectAttributes.HTTPS |

                    NaController.ConnectAttributes.Transient).First();

                MessageBox.Show("Success", "NetApp Proxy Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);

       }

            catch (Exception ex)

       {

                MessageBox.Show("Error: " + ex.Message, "NetApp Proxy Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

       }

Thanks,

Rob

View solution in original post

2 REPLIES 2

rbarker

Just to be sure my PSCredential object is being set properly via SecureString I added the following code to unpack the SecureString and it is correct. The credentials are correct to log into the controller so not sure why my C# code is throwing this error. I call the below code with a MessageBox.Show(SecureStringToString(pwd)) and it shows the correct net@pp1.

static String SecureStringToString(SecureString value)

{

IntPtr bstr = Marshal.SecureStringToBSTR(value);

try

{

return Marshal.PtrToStringBSTR(bstr);

}

finally

{

               Marshal.FreeBSTR(bstr);

}

}

Thanks,

Rob

rbarker

Answered my own question but definitely with a head scratch. Modified code below; the only difference in the code is that I am reading the 3 parameters (controller IP/name, login and password) into string variables then using the resulting stored strings in my calls and everything works no problem.

       Proxy ontap = new Proxy();

            string IP = textBox1.Text.ToString();

            string login = textBox2.Text.ToString();

            string password = textBox3.Text.ToString();

            SecureString secpwd = new SecureString();

            foreach (char c in password)

       {

            secpwd.AppendChar(c);

       }

            PSCredential Credential = new PSCredential(login, secpwd);

           

       try

       {

                var controller = ontap.NaController.Connect(IP, null, Credential, commandSwitches:

                    NaController.ConnectAttributes.HTTPS |

                    NaController.ConnectAttributes.Transient).First();

                MessageBox.Show("Success", "NetApp Proxy Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);

       }

            catch (Exception ex)

       {

                MessageBox.Show("Error: " + ex.Message, "NetApp Proxy Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

       }

Thanks,

Rob

View solution in original post

Announcements
Register for Insight 2021 Digital

INSIGHT 2021 Digital: Meet the Specialists 2

On October 20-22, gear up for a fully digital, totally immersive virtual experience with a downright legendary lineup of world-renowned specialists. Tune in for visionary conversations, solution deep dives, technical sessions and more.

NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public