This article deals with how to create a Windows Form Application in C# as a Login Page which basically all applications contain as the starting page, where users will be validated for their passwords.
Open Visual Studio 2015 and click on File –> New –> Project which opens up the template window with many developing options.
The above step brings in an empty Windows Form where the user can use Tools for designing the empty form into interactive form. I have used Label (2 nos), TextBox (2 nos) and a Button . Placing the tools in the right designing way, it looks like the below image.
The conventional way of any login form will contain password displayed in a special character which is for security purposes. To bring that concept into your login form, select the Properties option of TextBox in which you could find the option Password Char where you can give your desired special character (in my case, I have used * asterisk). By making this change, if you run your application, it will display only the special symbol when you enter a password.
Now, it is time for creating the repository for your login form. For this, go to Start menu and find the MS Access and click once to open.
public partial class Form1 : Form
private void btnLogin_Click(object sender, EventArgs e)
string usr = txtUser.Text;
string psw = txtPass.Text;
con = new OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=dbUsers.accdb");
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM tblUser where user='" + txtUser.Text + "' AND pass='" + txtPass.Text + "'";
dr = cmd.ExecuteReader();
Form2 f2 = new Form2();
MessageBox.Show("Username or password is incorrect");