What is the best mechanism for storing authentication settings in a WinForms application

I have an application that will send authenticated emails using System.Net.Mail and System.Net.NetworkCredential. The question is, how do I store the password needed to create the NetworkCrednetial object?

There is no login in the application, but I can configure a parameter that allows the user to enter their email credentials (in almost all cases this will be their Windows login). I cannot use Active Directory because not every client uses it.

I can get the password from the user, and then save it in the user registry, file or database. Obviously, I will have to encrypt it. I'm not very good at encryption, so some pointers will be appreciated if people think this is the best mechanism.

My preference would be to avoid having to store anything, so anyway I can get around to store the credentials myself, maybe I can get it from the current login or somewhere else?

+6
c # winforms email-integration
source share
2 answers

To save the username and password (on Windows), use DPAPI . The .Net interface for it is ProtectedData and the ProtectedMemory classes.

But first, you can try if UseDefaultCredentials or DefaultNetworkCredentials works for your environment.

+3
source share

You can also use the Win32 Credentials user interface - there are several selections for using this from .NET, including this one on MSDN .

0
source share

All Articles