[C#] Very Easy TUT: How to use a login feature for your app

 I decided to create this login system. This does not require a database and/or internet connection. Everything is stored locally.
Step [1]
Create a new project. - C#
[​IMG]
Step [2]
Add the following components(if you wish to follow mine exactly)
2 - Textboxs
2 - Buttons
1 - Checkbox
[​IMG]
Step [3]
Go to the projects properties, and then application settings. Here we are going to add three settings. Two strings and one int. I'm sure there are better ways of doing this, but this is how I do things. So no need to flame your flame-thrower.
Name them as you wish, but remember then name(s).
[​IMG]
Step [4]
Now in the forms load event, we check to see if the settings have been set or changed. You only need to check for the username as everything saves or nothing.
Code (Text):
        private void Form1_Load(object sender, EventArgs e)
        {
            // Check to see if settings have been saved or changed.
            if (Properties.Settings.Default.Username != string.Empty)
            {
                textBox1.Text = Properties.Settings.Default.Username;
                textBox2.Text = Properties.Settings.Default.Password;
                checkBox1.Checked = true;
            }
        }
Step [5]
Now for the checkbox_Checked event, we save all the information within the text boxes. This is where the isChecked setting comes into play. When we are checked, ischecked is equal to one. 
Code (Text):
        private void checkBoxX1_CheckedChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.Username = textBox1.Text
            Properties.Settings.Default.Password = textBox2.Text
            Properties.Settings.Default.isChecked = 1;
            Properties.Settings.Default.Save();
        }
Step [6]
Okay so the username and password are now being saved. It's time to add some functionality to the login button. To do this, I'm going to create one universal password which is going to be "Se7enSins". Start by creating a string called password, Se7enSins. There is only one string, which we are checking for, because in reality, the username can be anything. We are only checking for the password.
[​IMG]
Step [7]
In the Login buttons click event, we are now checking to see if the text within the textbox is the same as the password string. If the password is the same, a message box will show "Correct" else an message box will show "Wrong" You can add more code after that, such as showing a new form, or resetting the textboxes.
Code (Text):
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == password)
            {
                MessageBox.Show("Correct");
                // Show your next form here
            }
            else
            {
                MessageBox.Show("Wrong");
                // Add some more code here if you wish
            }
        }
Here is the complete code, if you wish to see how everything is constructed. Don't simply copy and paste what's in the spoilers. Try to understand how it works, if you are new to C#. Thanks for reading.
[​IMG]
[​IMG]

1 comment:

  1. Fbi-Tutorials: [C] Very Easy Tut: How To Use A Login Feature For Your App >>>>> Download Now

    >>>>> Download Full

    Fbi-Tutorials: [C] Very Easy Tut: How To Use A Login Feature For Your App >>>>> Download LINK

    >>>>> Download Now

    Fbi-Tutorials: [C] Very Easy Tut: How To Use A Login Feature For Your App >>>>> Download Full

    >>>>> Download LINK 11

    ReplyDelete