The following is sample C# code from the MOSS SDK:
string[] rgGetCredentialData = new string[2];
SpsSsoProvider provider = (SpsSsoProvider)SsoProviderFactory.GetSsoProvider();
SsoCredentials credentials = provider.GetCredentials(appName);
IntPtr pUserName = IntPtr.Zero;
IntPtr pPassword = IntPtr.Zero;
try
{
pUserName = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(credentials.UserName);
rgGetCredentialData[0] = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(pUserName);
pPassword = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(credentials.Password);
rgGetCredentialData[1] = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(pPassword);
}
finally
{
if (IntPtr.Zero != pUserName)
{
System.Runtime.InteropServices.Marshal.ZeroFreeBSTR(pUserName);
}
if (IntPtr.Zero != pPassword)
{
System.Runtime.InteropServices.Marshal.ZeroFreeBSTR(pPassword);
}
}
Advertisements