[C#] Easy - Alternative login

Discussion in 'Source Code & Tutorial Database' started by Kizzyiee, Feb 5, 2013 with 4 replies and 1,087 views.

  1. Kizzyiee

    Kizzyiee Sin Tool - DEV

    Messages:
    269
    Ratings:
    126
    After seeing DArK x1337HaX's tutorial, I decided to create this login system. This does not require a database and/or internet connection. Everything is stored locally. You can view his tutorial here.
    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:
            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:
            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:
            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]

     
  2. GoldBl4d3

    GoldBl4d3 VIP VIP Retired

    Messages:
    3,778
    Ratings:
    1,345
    Nice tutorial. Its not really a safe way to store passwords, even if it is locally.
     
  3. Mimz

    Mimz Just figured this out.I'm a smart cookie.12/27

    Messages:
    291
    Ratings:
    58
    Actually, I've heard this before. I've never looked into safer options.
    Can you PM me some alternative methods? I may look into them later.
    I've used:
    -This method
    -MYSQL
    -Online file scraping

    OT: Great TUT. I've personally never made many logins. I completely forgot about this method.
     
  4. DArK x1337HaX

    DArK x1337HaX 4D 79 20 4E 61 6D 65 20 49 73 20 44 61 6E

    Messages:
    2,732
    Ratings:
    1,034
    Great TUT! I really like your gui xD Great job!
     
  5. Z61

    Z61 Some times our saints are sinners Retired

    Messages:
    5,521
    Ratings:
    3,058
    Atleast md5 the password if you didn't.
     
    • Like Like x 1

Share This Page