3

I want to add a "Remember Me" check box to the login form of my WPF App. What's the best way to do this?

Currently the app logs in via a websevice call that returns an authenticated token that it uses for subsequent calls. Should I simply two-way encrypt and store this token somewhere in the files system?

Mark Boltuc
  • 3,487
  • 1
  • 27
  • 26
  • http://stackoverflow.com/questions/22435561/encrypting-credentials-in-a-wpf-application/22435672#22435672 – meziantou Mar 18 '14 at 17:09

3 Answers3

3

You could also store it in Isolated Storage or create a User setting in your application's Settings.

Edit: Oren's suggestion of using DPAPI to protect information is well and good, but it doesn't store anything:

An important point to remember is that DPAPI merely applies cryptographic protection to the data. It does not store any of the protected data; therefore applications calling DPAPI must implement their own storage of the protected data.

Joel B Fant
  • 24,406
  • 4
  • 66
  • 67
3

Use the DPAPI. See also How to store passwords in Winforms application?.

Community
  • 1
  • 1
Oren Trutner
  • 23,752
  • 8
  • 54
  • 55
1

I googled another solution:

Right click on your Project -> Properties -> Setting.

Add your variable which you need to store on client machine.

For example:

Name Type Scope Value

UserName String User
Password String User

Then, for example, you want to save preference on login button click:

If(CheckboxRemember.checked)
{
    YourProjectNamespace.Properties.Settings.Default.UserName = TextBoxUserName.Text;
    YourProjectNamespace.Properties.Settings.Default.Password = TextPassword.Text;
    YourProjectNamespace.Properties.Settings.Default.Save();
}

On the same way, access these value on window load or application startup:

TextBoxUserName.Text = YourProjectNamespace.Properties.Settings.Default.UserName;
TextPassword.Text = YourProjectNamespace.Properties.Settings.Default.Password;
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68