What's new

[C#] Easy - Alternative login

Kizzyiee

Sin Tool - DEV
Messages
269
Reaction score
130
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#
Step [2]
Add the following components(if you wish to follow mine exactly)
2 - Textboxs
2 - Buttons
1 - Checkbox
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).
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.
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.
 

GoldBl4d3

VIP
VIP
Retired
Messages
3,789
Reaction score
1,440
Nice tutorial. Its not really a safe way to store passwords, even if it is locally.
 

Mimz

Just figured this out.I'm a smart cookie.12/27
Messages
282
Reaction score
60
Nice tutorial. Its not really a safe way to store passwords, even if it is locally.
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.
 

Z61

Some times our saints are sinners
Retired
Messages
5,528
Reaction score
3,424
Atleast md5 the password if you didn't.
 
Top Bottom