views:

240

answers:

2

I have an App that will send authenticated emails using System.Net.Mail and System.Net.NetworkCredential my question is how should I store the password that is needed to create a NetworkCrednetial object?

The application doesn't have a login but I could setup an option that allows the user to enter their email credentials (in almost all cases this will be their windows login). I can't use Active Directory because not every customer uses it.

I could get the password from the user and then persist it to the users registry, a file or a database. Obviously i'd have to encrypt it. I'm not very familiar with encryption so some pointers would be appreciated if people think thats the best mechanism.

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

+3  A: 

To store a username and password (in Windows) use the DPAPI. The .Net interface to it is the ProtectedData and ProtectedMemory classes.

But first, you could try if the UseDefaultCredentials or DefaultNetworkCredentials is working for your environment.

GvS
This isn't my ideal solution but seems to be the best option. DefaultCredentials won't work for me but I'll request the password and store it using ProtectedData class. Thanks
Michael Prewecki
A: 

You could also use the Win32 Credentials UI - there exist a number of samples for using this from .NET, including this one on MSDN.

Joe