0

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???

Harish Kumar
  • 2,015
  • 4
  • 18
  • 18
  • 1
    Note that whatever method you choose, I recommend you don't store passwords in plain-text. In fact, coming up with your own mechanism for storing passwords at all (without a lot of "best practice" design input) is generally dangerous. – Merlyn Morgan-Graham Nov 13 '11 at 02:02
  • Possible duplicate of [Best practice to save application settings in a Windows Forms Application](http://stackoverflow.com/questions/453161/best-practice-to-save-application-settings-in-a-windows-forms-application) – DavidRR Nov 12 '15 at 14:46

3 Answers3

1

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;
Anuraj
  • 18,859
  • 7
  • 53
  • 79
0

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

DeveloperX
  • 4,633
  • 17
  • 22
0

You should save the information into a file in any of the following directories:

  • ApplicationData
  • LocalApplicationData

See Environment.SpecialFolder.

DavidRR
  • 18,291
  • 25
  • 109
  • 191
Yahia
  • 69,653
  • 9
  • 115
  • 144