Introduction
In this article i will give an example of login form using entity framework. We will do login from database table so first of all create database table using entity framework's code first approach. Now, Using linq query we can do this task.
Description
Sometimes anonymous user can
harm our application and can change the data stored in our application. That’s
why, it is often necessary to permit only authorized users to use our
application. There is no predefined method
to do this operation in windows forms, so we have to implement it in our way.
If
we have username and password in our database then we can implement a better authentication system. So we will create a table in
our database named User which will have two columns (Username and Password). Insert some records in that table to check
our login control.
In click event of login
button write following code:
Here in this code will show a
message if user leaves the textboxes empty. First check the username in our
database having exactly the same name user entered in textbox. If there is an entry
then compare the password.
We can show a message box at
each wrong step of user.
Download example.