saving user state in MVVM application

1.1k Views Asked by At

I am creating a MVVM application and the basic system allows a user to register, login, and add data to a database.

There are multiple users, so I want the system to be able to maintain the user's credentials/state after they login and have the application open.

So far I haven't been able to find any good tutorials online to advise me about this, so if anyone knows any or knows of a way to do this I would really appreciate some help.

Thanks.

3

There are 3 best solutions below

0
On

You can use application settings as a store for user state and credentials. To store settings in user's profile, you should set corresponding scope for each setting you'll define.

Consider settings as a part of application model (Model in MVVM). Build model when starting application, using application settings, and save it on application shutdown.

Also, do not store passwords in clear text. Use ProtectedData to encrypt and decrypt passwords.

4
On

Use cookies or local storage are 2 things that jump out to me.

0
On

Simply, after receiving the username and password of the user, if the credentials are correct generate a guid and save it to db for that user and add this guid in cookies also. And on every request search the guid value in db and authorize the user if the guid is existing.