Пример #1
0
        private async void BtnLogin_Click(object sender, EventArgs e)
        {
            string username = tbLoginEmail.Text;
            string password = tbLoginPassword.Text;

            if (username == "")
            {
                lblLoginError.ForeColor = System.Drawing.Color.Red;
                lblLoginError.Text      = "Email is required";
                tbRegisterEmail.Focus();
                tbRegisterEmail.SelectAll();
            }

            else
            {
                if (password == "")
                {
                    lblLoginError.ForeColor = System.Drawing.Color.Red;
                    lblLoginError.Text      = "Password is required";
                    tbLoginPassword.Focus();
                    tbLoginPassword.SelectAll();
                }

                else
                {
                    string hashedPass = dataUtility.EncodePassword(password);

                    Task <bool> loginAsync = dataLogin.loginToDatabase(username, hashedPass);

                    progressBarLogin.Visible = true;
                    progressBarLogin.MarqueeAnimationSpeed = 10;

                    bool loginSuccess = await loginAsync;

                    if (loginSuccess)
                    {
                        frmPasswordRetrieval newForm = new frmPasswordRetrieval();
                        newForm.Show();
                        newForm.Location = this.Location;

                        //close login form
                        this.Close();
                    }

                    else
                    {
                        lblLoginError.ForeColor = System.Drawing.Color.Red;
                        lblLoginError.Text      = "Incorrect Password";

                        tbLoginPassword.Focus();
                        tbLoginPassword.SelectAll();
                    }

                    progressBarLogin.Visible = false;
                }
            }
        }
        //when back button is pressed
        private void BtnBack_Click(object sender, EventArgs e)
        {
            frmPasswordRetrieval newForm = new frmPasswordRetrieval();

            newForm.Show();
            newForm.Location = this.Location;

            //close login form
            this.Close();
        }