Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using System.IO;
- namespace MyForm
- {
- public class Login : Form
- {
- private Button btLogin;
- private Button btIndex;
- private TextBox username;
- private TextBox password;
- private Label un;
- private Label pw;
- private CheckBox chPass;
- public Login()
- {
- InitializeComponents();
- }
- public void InitializeComponents()
- {
- this.Text = "Login Form";
- this.BackColor = Color.Lavender;
- this.ForeColor = Color.Black;
- this.Size = new Size(250, 300);
- this.StartPosition = FormStartPosition.CenterScreen;
- btLogin = new Button();
- btLogin.Text = "Login";
- btLogin.Location = new Point(80, 180);
- btLogin.Click += btLogin_Click;
- btIndex = new Button();
- btIndex.Text = "Back";
- btIndex.Location = new Point(80, 210);
- btIndex.Click += btIndex_Click;
- un = new Label();
- un.Text = "Username";
- un.Location = new Point(20, 80);
- username = new TextBox();
- username.Text = "";
- username.MaxLength = 10;
- username.Location = new Point(80, 80);
- pw = new Label();
- pw.Text = "Password";
- pw.Location = new Point(20, 110);
- password = new TextBox();
- password.Text = "";
- password.UseSystemPasswordChar = true;
- password.Location = new Point(80, 110);
- chPass = new CheckBox();
- chPass.Location = new Point(79, 130);
- chPass.Text = "Show Password";
- chPass.UseVisualStyleBackColor = true;
- chPass.CheckedChanged += new System.EventHandler(chPass_CheckedChanged);
- this.Controls.Add(username);
- this.Controls.Add(password);
- this.Controls.Add(btLogin);
- this.Controls.Add(un);
- this.Controls.Add(pw);
- this.Controls.Add(chPass);
- this.Controls.Add(btIndex);
- }
- public void btLogin_Click(object sender, EventArgs e)
- {
- string path = String.Concat("", username.Text, ".txt");
- string[] user = new string[2];
- if (username.Text == "" || password.Text == "")
- {
- MessageBox.Show("No username/password. \nPlease input your log-in credentials.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- if (!File.Exists(path))
- {
- MessageBox.Show("Please input a valid username.", "Invalid Username", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- else
- {
- using (StreamReader sr = new StreamReader(path))
- {
- for (int i = 0; i < user.Length; i++)
- {
- user.SetValue(sr.ReadLine(), i);
- }
- }
- if ((string)(user.GetValue(0)) != password.Text)
- {
- MessageBox.Show("Please input the correct password.", "Incorrect Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- else
- {
- if ((string)(user.GetValue(1)) == "Type One")
- {
- TypeOne one = new TypeOne();
- this.Hide();
- one.Show();
- }
- else
- {
- password.UseSystemPasswordChar = true;
- TypeTwo two = new TypeTwo();
- this.Hide();
- two.Show();
- }
- }
- }
- }
- public void btIndex_Click(object sender, EventArgs e)
- {
- Index ind = new Index();
- ind.Show();
- this.Hide();
- }
- private void chPass_CheckedChanged(object sender, EventArgs e)
- {
- if (chPass.CheckState == CheckState.Checked)
- password.UseSystemPasswordChar = false;
- else
- password.UseSystemPasswordChar = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment