Reputation: 2105
I am using a C# windows forms application. When I launch the project, a dialog box will appear with menus. In a particular menu, I choose Options and Options dialog box opens. Inside that, I need to enter a username and password and validate it against the DB. If credentials are correct, I should make a login form to display (I have login form as part of my project), upon closing the project and running it the next time. How do I go about doing this?
How and where should I store the result of the validation of username and password and make the project remember to launch the login form, when I launch the project next time???
Upvotes: 0
Views: 206
Reputation: 70369
You should save the information into a file in any of the following directories:
ApplicationData
LocalApplicationData
See Environment.SpecialFolder.
Upvotes: 0
Reputation: 19598
You can try Project Properties > Settings option. VS will generate class for the settings and you can access them via Properties.Settings.Default.[PropertyName]
if(chkRememberMe.Checked)
{
Properties.Settings.Default.Username = txtUsername.Text;
Properties.Settings.Default.Password = txtPassword.Text;
Properties.Settings.Default.Save();
}
And while loading back
txtUsername.Text = Properties.Settings.Default.Username;
txtPassword.Text = Properties.Settings.Default.Password;
Upvotes: 1
Reputation: 4683
use the app config file to save local application data How to: Add Application Configuration Files to C# Projects and this is usefull How to use appconfig
Upvotes: 0