Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string path = @"D:\MyTest.txt";

            if (!this.ValidatePassword())
            {
                MessageBox.Show("Password not same! Please enter");
            }
            else
            {
                try
                {
                    if (!File.Exists(path))
                    {
                        File.WriteAllText(path, txtUserName.Text + "\t" + Login.ConvertMD5Hash(txtRgtPassword.Text) + Environment.NewLine);
                    }
                    File.AppendAllText(path, txtUserName.Text + "\t" + Login.ConvertMD5Hash(txtRgtPassword.Text) + Environment.NewLine);
                    MessageBox.Show("register successfull!");
                    this.Hide();
                    RichTextBoxForm rbf = new RichTextBoxForm();
                    rbf.Show();
                }
                catch
                {
                    MessageBox.Show("not success!");
                }
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int flat = 0;

            try
            {
                string path = @"D:\MyTest.txt";

                IEnumerable <String> readText = File.ReadAllLines(path);
                foreach (string text in readText)
                {
                    int index = text.IndexOf("\t");
                    this.UserVld     = text.Substring(0, index);
                    this.PasswordVld = text.Substring(index + 1);
                    Login  login = new Login(UserVld, PasswordVld);
                    string user  = textBox1.Text;
                    string pass  = Login.ConvertMD5Hash(textBox2.Text);
                    //check if eligible to be logged in
                    if (login.IsLoggedIn(user, pass))
                    {
                        this.Hide();
                        RichTextBoxForm f2 = new RichTextBoxForm();
                        f2.ShowDialog();
                        flat = 1;
                    }
                }
            }
            catch
            {
                MessageBox.Show("Login Error!");
            }
            if (flat == 0)
            {
                MessageBox.Show("Login Failed!");
            }



            //show default login error message
        }