How to Create a Simple Login System in C#
Submitted by janobe on Wednesday, October 3, 2018 - 21:33.
In this tutorial, I will teach you how to create a simple login system in c#. This simple login system is a good start when you begin to program for the security of your application. This has a default username and password that can be used when you log in. See the procedure below.
The complete source code is included. You can download it and run it on your computer.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
FB Account – https://www.facebook.com/onnaj.soicalap
Creating application
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application in c#. After that, do the form just like shown below.Step 2
Double click the form and hide the “Logout” button and “username” label in the first load of the form.- lblUsername.Visible = false;
- button2.Visible = false;
Step 3
Go back to the design views, double click the “Login” button and do the following codes in the click event handler
of a button to fire the method when its clicked.
- string str_username;
- string str_password;
- str_username = "itsourcecode.com";
- str_password = "admin";
- if(textBox1 .Text == str_username && textBox2 .Text == str_password)
- {
- MessageBox.Show("Login successfully");
- lblUsername.Visible = true;
- button2.Visible = true;
- lblUsername.Text ="Howdy, " + str_username;
- label1.Visible = false;
- label2.Visible = false;
- textBox1.Visible = false;
- textBox2.Visible = false;
- button1.Visible = false;
- }else
- {
- MessageBox.Show("Account does not exist.");
- }
Step 4
Do the following code for the “Logout” button.- private void button2_Click(object sender, EventArgs e)
- {
- label1.Visible = true;
- label2.Visible = true;
- textBox1.Visible = true;
- textBox2.Visible = true;
- button1.Visible = true;
- lblUsername.Visible = false;
- button2.Visible = false;
- textBox1.Text = "";
- textBox2.Text = "";
- textBox1.Focus();
- }
Add new comment
- 3169 views