There is a WPF application, divided into three parts according to the MVVM pattern. The application works with the MySql database using the Entity Framework 6. The need to authorize users in the application has appeared. Each user is not just an entry in the Users table of the database, he is also a user at the DBMS level (he did this for differentiating rights to certain tables and for writing to logs). So, how to implement the following functionality in accordance with MVVM:
- when starting, display an authorization window, where the user enters his username and password;
- then, using the entered login and password, generate a connection string, through which the EF context will be connected to the database. It is important to do this in such a way that it is possible in the code to quickly and conveniently pass this string into context;
- continue to try to log in to the DBMS and, if the authorization is successful, to work under this user (there are triggers in the database that write change logs that use the CURRENT_USER function many times);
- storing the connection string somewhere in the file is highly undesirable, because This will have a bad effect on safety and even on speed.