Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 686
Michael Prewecki Avatar asked Nov 05 '08 11:11

Michael Prewecki


1 Answers

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.

like image 186
GvS Avatar answered Oct 13 '22 09:10

GvS