コード例 #1
0
        private void backgroundWorkerUpdatePassword_DoWork(object sender, DoWorkEventArgs e)
        {
            string userType = MathWizDA.FindUserType(username_G);

            switch (userType)
            {
            case "admin": user = new Admin(); break;

            case "teacher": user = new Teacher(); break;

            case "parent": user = new Parent(); break;

            case "student": user = new Student(); break;
            }
            string passwordHash = user.HashPassword(txtNewPassword.Text);

            MathWizDB.UpdatePassword(userType, username_G, passwordHash);
        }
コード例 #2
0
        private void backgroundWorkerLogin_DoWork(object sender, DoWorkEventArgs e)
        {
            string userType = MathWizDA.FindUserType(txtUsername.Text);

            if (userType == "admin")
            {
                user = new Admin();
                if (user.VerifyPassword(txtUsername.Text, txtPassword.Text))
                {
                    errorFlag = "";
                    homeForm  = new frmAdminHome(txtUsername.Text);
                }
                else
                {
                    errorFlag = "password";
                }
            }
            else if (userType == "teacher")
            {
                user = new Teacher();
                if (user.VerifyPassword(txtUsername.Text, txtPassword.Text))
                {
                    errorFlag = "";
                    homeForm  = new frmTeacherHome(txtUsername.Text);
                }
                else
                {
                    errorFlag = "password";
                }
            }
            else if (userType == "parent")
            {
                user = new Parent();
                if (user.VerifyPassword(txtUsername.Text, txtPassword.Text))
                {
                    errorFlag = "";
                    homeForm  = new frmParentHome(txtUsername.Text);
                }
                else
                {
                    errorFlag = "password";
                }
            }
            else if (userType == "student")
            {
                user = new Student();
                if (user.VerifyPassword(txtUsername.Text, txtPassword.Text))
                {
                    errorFlag = "";
                    homeForm  = new frmStudentHome(txtUsername.Text);
                }
                else
                {
                    errorFlag = "password";
                }
            }
            else if (userType == "none") //could not find username
            {
                errorFlag = "username";
            }
            else //the sql statement must have had an error
            {
                MessageBox.Show("Login Error. We could not verify your username, but this may be due to a slow connection", "Connection Error");
            }
        }