Home > Back-end >  Start App with Same User Account after System Restart winforms
Start App with Same User Account after System Restart winforms

Time:11-15

The Main Problem: I am working on a multi-user WinForms application(Multi-users and an Admin). All I want to know is how to make the application remember the user's account who has logged in to the app even after the system restart.

My Try: I tried it by saving the user's data on a file and reading the user's details(not password) to log in to the app and when the user logs out the file is deleted. Even the file is encrypted, if some of the data is changed, it will ruin the entire experience of the app. It can be both running at system startup or run manually by the user after system restart.

Possible Alternatives: Is there any built-in approach or generally followed mechanism for the scenario?

Thanks in advance Guys!

CodePudding user response:

  • Open the login form
  • Click the username box
  • Go to the properties grid and scroll it up to the top
  • Find the (Application settings) line and expand it to reveal (Property Binding)
  • Click the 3 dots and find Text in the list that popped up
  • Drop it down to reveal a New.. option
  • give it some name like DefaultUserName and ensure it is User scoped
  • ok/ok out of those so you're back at the form
  • Click on the form so it is selected
  • Switch the property grid to Events (lightning bolt) view
  • Double click FormClosing event
  • Write code Properties.Settings.Default.Save()

This stores the last user login name only, for the currently logged on windows user.. like a "remember me" box on the web. It doesn't keep a history of everything ever typed into the username box, and it doesn't remember settings across different windows user logins (both those things would be a security issue, really) - it just offers a nice convenience of repeat users not having to type their same username in again and again

  • Related