Ejemplo n.º 1
0
        public bool VerifyPassword(string username, string password)
        {
            //get the password hash from the database
            string passwordHash = MathWizDA.SelectPasswordHash(username);

            //turn the passwordHash string into a byte array again
            byte[] hashBytes = Convert.FromBase64String(passwordHash);

            //extract the salt from the hash byte array --keep numbers the same!!
            byte[] salt = new byte[16];
            Array.Copy(hashBytes, 0, salt, 0, 16);

            //compute the hash on the password that the user entered -- needs to use the salt that was just extracted!! and the same # of iterations!!
            var pbkdf2 = new Rfc2898DeriveBytes(password, salt, 10000);

            byte[] hash = pbkdf2.GetBytes(20);

            //if the hashes do not match, then return false, otherwise return true to verify the password
            for (int i = 0; i < 20; i++)
            {
                if (hashBytes[i + 16] != hash[i]) //for some reason it needs to check != or else there were false positives 10% of the time
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        private void btnDeleteTest_Click(object sender, EventArgs e)
        {
            int testID = Convert.ToInt32(dgvTests.Rows[dgvTests.CurrentCell.RowIndex].Cells[0].Value);
            int gradedTestID;

            DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this test?", "Confirm Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dialogResult == DialogResult.Yes) //delete the test if they confirm yes
            {
                // Grab the graded_test id with the test id (I'm assuming/hoping that testid is unique with this select)
                gradedTestID = MathWizDA.SelectGradedTestIDViaTestID(testID);

                //Delete the Graded Questions with the Graded Test ID
                MathWizDB.DeleteGradedQuestions(gradedTestID);

                //Delete the actual Graded Test with the Standard Test ID
                MathWizDB.DeleteGradedTestWithTestID(testID);

                //Delete Normal Questions with the Standard Test ID
                MathWizDB.DeleteNormalQuestions(testID);

                //Finally, delete the normal standard test
                MathWizDB.DeleteNormalTest(testID);
            }
        }
Ejemplo n.º 3
0
        private void backgroundWorkerLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            klass = MathWizDA.SelectStudentsKlass(student.Id);

            if (student.MasteryLevel == 0) //if student has not taken placement test yet, only load that test
            {
                availablePlacementTest = MathWizDA.SelectKlassesPlacementTest(klass.Id);
            }
            else //load the tests that the student can take, but not the placement test since they already took it
            {
                availableMasteryTests = MathWizDA.SelectKlassesMasteryTests(klass.Id);
            }
        }
Ejemplo n.º 4
0
        private void btnCreateUser_Click(object sender, EventArgs e)
        {
            if (txtFirstName.Text == "")
            {
                MessageBox.Show("First Name is Required");
            }
            else if (txtLastName.Text == "")
            {
                MessageBox.Show("Last Name is Required");
            }
            else if (txtUsername.Text == "")
            {
                MessageBox.Show("Username is Required");
            }
            else if (txtPassword.Text == "")
            {
                lblPasswordError.Show();
            }
            else if (cmbParent.SelectedIndex == -1 && this.Tag.ToString() == "Student")
            {
                MessageBox.Show("A student must have a parent. If a the parent is not listed here, make their account first.");
            }
            else if (cmbClass.SelectedIndex == -1 && this.Tag.ToString() == "Student")
            {
                MessageBox.Show("A student must be added to class.");
            }
            else if (MathWizDA.FindUsername(txtUsername.Text))
            {
                lblUsernameError.Text = "That username has already been taken";
                lblUsernameError.Show();
            }
            else //info is valid
            {
                btnCreateUser.Enabled = false;

                firstName = txtFirstName.Text;
                lastName  = txtLastName.Text;
                username  = txtUsername.Text;
                password  = txtPassword.Text;
                if (this.Tag.ToString() == "Student")
                {
                    parentID = parentChoices[cmbParent.SelectedIndex].Id;
                    klassID  = klassChoices[cmbClass.SelectedIndex].Id;
                }

                if (!backgroundWorkerInsertData.IsBusy)
                {
                    backgroundWorkerInsertData.RunWorkerAsync();
                }
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private void cmbKlasses_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbKlasses.SelectedIndex != -1 && cmbKlasses.SelectedItem != null)
            {
                currentKlass = cmbKlasses.SelectedItem as Klass;
                this.studentsTableAdapter.FillByKlass(this.mathWizGroup3DataSet.students, currentKlass.Id);
                this.testsTableAdapter.FillByKlassID(this.mathWizGroup3DataSet.tests, currentKlass.Id);

                // Check if the class has any placement tests created
                bool hasPlacementTests = true;
                hasPlacementTests = MathWizDA.FindPlacementTest(currentKlass.Id);
                if (hasPlacementTests == true)
                {
                    btnCreateTest.Enabled = false;
                    btnCreateTest.Text    = "Placement Test is already generated.";
                    btnCreateTest.Height  = 60;
                }
                else if (hasPlacementTests == false)
                {
                    btnCreateTest.Enabled = true;
                    btnCreateTest.Text    = "Create Placement Test";
                    btnCreateTest.Height  = 39;
                }


                // Check if the class has any mastery tests created
                bool hasMasteryTestsCreated = true;
                hasMasteryTestsCreated = MathWizDA.FindMasteryTest(currentKlass.Id);
                if (hasMasteryTestsCreated == true)
                {
                    btnGenerateMasteryTests.Enabled = false;
                    btnGenerateMasteryTests.Text    = "Mastery Tests are already generated.";
                    btnGenerateMasteryTests.Height  = 60;
                }
                else if (hasMasteryTestsCreated == false)
                {
                    btnGenerateMasteryTests.Enabled = true;
                    btnGenerateMasteryTests.Text    = "Generate All Mastery Tests";
                    btnGenerateMasteryTests.Height  = 39;
                }

                UpdateKlassInfo();
            }
        }
Ejemplo n.º 7
0
 private void backgroundWorkerLoadData_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         backgroundWorkerLoadData.ReportProgress(1);
         teacher.Klasses = MathWizDA.SelectAllKlassesByTeacher(teacher.Id);
         backgroundWorkerLoadData.ReportProgress(25);
         this.studentsTableAdapter.Fill(this.mathWizGroup3DataSet.students);
         backgroundWorkerLoadData.ReportProgress(50);
         this.graded_testsTableAdapter.Fill(this.mathWizGroup3DataSet.graded_tests);
         this.graded_questionsTableAdapter.Fill(this.mathWizGroup3DataSet.graded_questions);
         backgroundWorkerLoadData.ReportProgress(75);
         //this.testsTableAdapter.FillByNotPractice(this.mathWizGroup3DataSet.tests); //no practice tests
         backgroundWorkerLoadData.ReportProgress(100);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Internet Connection Error. This form will close. Try logging in again", "Error");
         this.Close();
     }
 }
Ejemplo n.º 8
0
 public frmAdminHome(string username)
 {
     InitializeComponent();
     admin = MathWizDA.SelectAdmin(username);
 }
Ejemplo n.º 9
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");
            }
        }
Ejemplo n.º 10
0
 private void backgroundWorkerLoadData_DoWork(object sender, DoWorkEventArgs e)
 {
     parent.Children = MathWizDA.SelectStudentsViaParent(parent.Id);
     this.studentsTableAdapter.Fill(this.mathWizGroup3DataSet.students);
 }
Ejemplo n.º 11
0
 //MARK Form load stuff
 public frmParentHome(string username)
 {
     InitializeComponent();
     parent = MathWizDA.SelectParent(username); //this has to go here
 }
Ejemplo n.º 12
0
 public frmTeacherHome(string username)
 {
     InitializeComponent();
     teacher = MathWizDA.SelectTeacher(username);
 }
Ejemplo n.º 13
0
 private void backgroundWorkerLoadData_DoWork(object sender, DoWorkEventArgs e)
 {
     parentChoices = MathWizDA.SelectAllParents();
     klassChoices  = MathWizDA.SelectAllKlasses();
 }
Ejemplo n.º 14
0
 private void backgroundWorkerLoadTeachers_DoWork(object sender, DoWorkEventArgs e)
 {
     allTeachers = MathWizDA.SelectAllTeachers();
 }