Ejemplo n.º 1
0
        private void btn_Continue_Click(object sender, EventArgs e)
        {
            SomerenLogic.Login_Service loginService = new SomerenLogic.Login_Service();
            List <Login> loginList = loginService.GetLogin();

            //to know whether a username has been matched with one from the databse
            int count = 0;

            foreach (var u in loginList)
            {
                if (u.UserName == textBox_username.Text)
                {
                    lbl_SecretQuestion.Text = u.SecretQuestion;
                    count++;
                    break;
                }
            }

            if (count == 0)
            {
                lbl_SecretQuestion.Show();
                lbl_SecretQuestion.Text = "Wrong username!";
            }
            else
            {
                lbl_SecretQuestion.Show();
                btn_Continue.Hide();
                textBox_Answer.Show();
                btn_Continue2.Show();
            }
        }
Ejemplo n.º 2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            SomerenLogic.Login_Service loginService = new SomerenLogic.Login_Service();
            List <Login> loginList = loginService.GetLogin();
            string       email     = txtUserName.Text;

            bool Isadmin = false;
            bool Isright = false;

            foreach (var s in loginList)
            {
                if ((s.UserName == txtUserName.Text) && (s.Password == txtPassword.Text))
                {
                    this.Hide();
                    if (s.Type == "admin")
                    {
                        Isadmin = true;
                    }
                    SomerenUI someren = new SomerenUI(Isadmin, $"{email}");
                    someren.ShowDialog();
                    this.Close();
                    break;
                }
                else
                {
                    Isright = true;
                }
            }
            if (Isright = true)
            {
                MessageBox.Show("Invalid user name or password!!!");
            }
        }
Ejemplo n.º 3
0
        private void btn_Reset_Click(object sender, EventArgs e)
        {
            SomerenLogic.Login_Service loginService = new SomerenLogic.Login_Service();
            List <Login> loginList = loginService.GetLogin();

            SomerenModel.Login login = new Login();

            foreach (var u in loginList)
            {
                if (u.UserName == textBox_username.Text)
                {
                    login = u;
                    break;
                }
            }

            //The requirements state that there should be at least 1 uppercase letter, 1 lowercase letter and a punctuation mark
            if (textBox_newPassword.Text.Any(c => char.IsUpper(c)) && textBox_newPassword.Text.Any(c => char.IsLower(c)) && textBox_newPassword.Text.Any(c => char.IsPunctuation(c)) && textBox_newPassword.Text.Count() >= 8)
            {
                //create new DAO
                SomerenDAL.Login_DAO login_DAO = new SomerenDAL.Login_DAO();

                //check if both a secret question and answer is present, if only one is was added, do not reset password
                if (!string.IsNullOrEmpty(textBox_newQ.Text) && !string.IsNullOrEmpty(textBox_newA.Text))
                {
                    login_DAO.ChangeSecretA(textBox_newA.Text, login.UserName);
                    login_DAO.ChangeSecretQ(textBox_newQ.Text, login.UserName);
                }
                else if (string.IsNullOrEmpty(textBox_newQ.Text) && !string.IsNullOrEmpty(textBox_newA.Text))
                {
                    MessageBox.Show("Please fill in both the secret question and secret answer!");
                    return;
                }
                else if (!string.IsNullOrEmpty(textBox_newQ.Text) && string.IsNullOrEmpty(textBox_newA.Text))
                {
                    MessageBox.Show("Please fill in both the secret question and secret answer!");
                    return;
                }
                else
                {
                    label10.Show();
                }

                login_DAO.ChangePassword(textBox_newPassword.Text, textBox_username.Text);
                label7.Hide();
                MessageBox.Show("Success!");
                this.Close();
            }
            else
            {
                label7.Show();
            }
        }
Ejemplo n.º 4
0
        private void btn_Continue2_Click(object sender, EventArgs e)
        {
            SomerenLogic.Login_Service loginService = new SomerenLogic.Login_Service();
            List <Login> loginList = loginService.GetLogin();

            SomerenModel.Login login = new Login();

            foreach (var u in loginList)
            {
                if (u.UserName == textBox_username.Text)
                {
                    login = u;
                    break;
                }
            }

            if (login.SecretAnswer == textBox_Answer.Text)
            {
                label3.Show();
                label4.Show();
                label5.Show();
                label6.Show();
                label9.Show();
                label8.Show();
                textBox_newPassword.Show();
                textBox_newQ.Show();
                textBox_newA.Show();
                btn_Reset.Show();
                btn_Continue2.Hide();
                label11.Show();
            }
            else
            {
                label2.Show();
            }
        }