Reputation: 3497
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?
Upvotes: 3
Views: 3880
Reputation: 11
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;
Upvotes: 1
Reputation: 24766
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.
Upvotes: 3
Reputation: 24218
Use the DPAPI. See also How to store passwords in Winforms application?.
Upvotes: 3