예제 #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            byte[] data = System.Text.Encoding.ASCII.GetBytes(textBox2.Text);
            data = new System.Security.Cryptography.SHA256Managed().ComputeHash(data);
            String hash = System.Text.Encoding.ASCII.GetString(data);

            CurrentUser.setCurrentUser(UserController.getAUser(textBox1.Text, hash));

            if (textBox1.Text.Trim().Equals("") || textBox2.Text.Trim().Equals(""))
            {
                MessageBox.Show("Please provide your username and password, or register below");
            }
            else if (CurrentUser.User == null)
            {
                counter++;
                MessageBox.Show("We couldn't find you. Please try again");
            }
            else
            {
                //this.Close();

                //homeForm = new homepageForm(CurrentUser.User);
                //homeForm.MdiParent = mainForm.Instance;
                //homeForm.WindowState = FormWindowState.Maximized;
                //homeForm.FormClosed += new FormClosedEventHandler(HomeForm_FormClosed);
                //homeForm.StartPosition = FormStartPosition.CenterScreen;
                //mainForm.Instance.setToolStripMenuItemsEnabled(true);
                //homeForm.Show();

                /* Begin fix*/
                this.Hide();
                var form2 = new mainForm(CurrentUser.User);
                form2.Closed += (s, args) => this.Close();
                form2.Show();
            }

            if (counter == 3)
            {
                DialogResult dialogResult = MessageBox.Show("Do you want to reset your password?", "Forgot Password?", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    counter = 0;
                    if (resetForm == null)
                    {
                        this.Hide();
                        resetForm = new resetPassword();
                        //resetForm.MdiParent = mainForm.Instance;
                        resetForm.FormClosed   += new FormClosedEventHandler(ResetForm_FormClosed);
                        resetForm.StartPosition = FormStartPosition.CenterScreen;
                        resetForm.Show();
                    }
                    else
                    {
                        resetForm.Activate();
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    counter = 0;
                    return;
                }
            }
        }