Esempio n. 1
0
 /*
  * Function to remove an account from the dbo.Admins.  This function calls the AdminLogin form as
  * additional authorization.  It is also unable to remove the base Administrator account as it should
  * not be an available option in the listbox.
  */
 private void removeButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (removeListBox.SelectedIndex != -1)
         {
             using (var myform = new AdminLogin())   //calling the AdminLogin form for additional security
             {
                 myform.ShowDialog();
                 if (myform.DialogResult == DialogResult.OK && (myform.authok == "Admin" || myform.authok == "Administrator"))
                 {
                     Valid admin = new Valid();
                     if (admin.RemoveAdmin(removeListBox.SelectedItem.ToString()))
                     {
                         MessageBox.Show("Selected admin removed.");
                         ListFill(true);
                         ListFill(false);
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }
Esempio n. 2
0
        private void confirmButton_Click(object sender, EventArgs e)
        {
            string password = passBox.Text;

            if (password.Length >= 8)
            {
                if (password == confirmBox.Text)
                {
                    Valid admin = new Valid();
                    if (admin.UpdateAdmin("Administrator", password))
                    {
                        MessageBox.Show("Administrator password has been updated successfully.");
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("An error has occured while updating Administrator password.");
                    }
                }
                else
                {
                    MessageBox.Show("Passwords do not match, please re-enter.");
                    passBox.Clear();
                    confirmBox.Clear();
                }
            }
            else
            {
                MessageBox.Show("Please enter a password of at least eight characters.");
                passBox.Clear();
                confirmBox.Clear();
            }
        }
Esempio n. 3
0
 /*
  * This is functionally identical to the AppendLog in the StudentLogin form with the exception
  * that is does not try to create a password entry in the log string
  */
 private bool AppendLog(Valid student)  //Will append a log file of the current date with student name
 {
     try
     {
         string   logDir    = Path.Combine(Environment.CurrentDirectory, "Logs");
         DateTime dt        = DateTime.Now;
         string   date      = dt.ToShortDateString();
         string   time      = dt.ToShortTimeString();
         string[] newdate   = (dt.Date.ToString()).Split();
         string[] dateparts = newdate[0].Split('/');
         date = dateparts[0] + "-" + dateparts[1] + "-" + dateparts[2];
         if (!Directory.Exists(logDir))
         {
             Directory.CreateDirectory(logDir);
         }
         string       logpath     = date + ".txt";
         StreamWriter outputfile  = new StreamWriter("Logs\\" + logpath, true); //look at how to specify directories
         string       encryptText = Utility.Encrypt(student.First + "," + student.Last + ",," + date + ",Forced: ," + time, false);
         outputfile.WriteLine(encryptText);
         outputfile.Close();
         return(true);
     }
     catch
     {
         MessageBox.Show("Error writing to log.");
     }
     return(false);
 }
Esempio n. 4
0
 /*
  * Similar to other ListFill methods present this is the method called on load and by other functions
  * to populate the listboxes with updated admin lists.  This method varies from the others in that
  * it requires a boolean value on this form, which is used to determine whether the listbox being
  * populated is associated with functions that can delete users from the dbo.Admins.
  */
 private void ListFill(bool delete)
 {
     if (delete)
     {
         removeListBox.Items.Clear();
         Valid         openFill   = new Valid();
         List <string> adminNames = new List <string>(openFill.AdminSearch(delete));
         if (adminNames.Count > 0)
         {
             for (int i = 0; i < adminNames.Count; i++)
             {
                 removeListBox.Items.Add(adminNames[i]);
             }
         }
     }
     else
     {
         updateListBox.Items.Clear();
         Valid         openFill   = new Valid();
         List <string> adminNames = new List <string>(openFill.AdminSearch(delete));
         if (adminNames.Count > 0)
         {
             for (int i = 0; i < adminNames.Count; i++)
             {
                 updateListBox.Items.Add(adminNames[i]);
             }
         }
     }
 }
Esempio n. 5
0
        }                                                   //maintains a global list of logged in students


        /*
         * This logout button functions similarly to the logout feature on the StudentLogin form with
         * the exception that it does not require the StudentID to be entered for password authentication.
         * This is due to the form only being accessible to lab assistants who do not have students
         * individual passwords to log them out with
         */
        private void outButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (loginListBox.SelectedIndex != -1)
                {
                    string   name      = loginListBox.SelectedItem.ToString();
                    string[] fullname  = name.Split(',');                   //tokenizes name for searching the DB
                    string   lastname  = fullname[0].Trim();
                    string   firstname = fullname[1].Trim();
                    Valid    student   = new Valid(firstname, lastname, null);
                    //create/append a log file with name, ID, major and timestamp
                    //add to a list for the logout page
                    if (AppendLog(student))
                    {
                        MessageBox.Show("Logout successful.");
                        currentStudents.Remove(name);
                        this.currentStudents = currentStudents;
                        this.DialogResult    = DialogResult.OK;
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Please select a student.");
                }
            }
            catch
            {
            }
        }
Esempio n. 6
0
        /*
         * The following region contains the methods that alter the table, including insertion and removal
         * methods for students and admins, and the update method to change Admin passwords.
         * They all function similarly, creating parameterized SQL commands to send to the respective database
         */

        #region TableManipulation

        public bool InsertStudent(Valid student)
        {
            try
            {
                string connectionstring = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Students.mdf;Integrated Security=True;Connect Timeout=30";
                using (SqlConnection sqlcon = new SqlConnection(connectionstring))
                {
                    SqlParameter fnameParam = new SqlParameter("@fname", SqlDbType.NVarChar, 50);
                    SqlParameter lnameParam = new SqlParameter("@lname", SqlDbType.NVarChar, 50);
                    SqlParameter passParam  = new SqlParameter("@password", SqlDbType.NVarChar, 50);
                    SqlCommand   cmd        = new SqlCommand();
                    string       insertname = "INSERT INTO dbo.Student (StudentID, FirstName, LastName) VALUES (@password, @fname, @lname);";
                    sqlcon.Open();
                    fnameParam.Value = student.First;
                    lnameParam.Value = student.Last;
                    passParam.Value  = Utility.Encrypt(student.Pass, false);
                    cmd.CommandText  = insertname;
                    cmd.Connection   = sqlcon;
                    cmd.Parameters.Add(passParam);
                    cmd.Parameters.Add(lnameParam);
                    cmd.Parameters.Add(fnameParam);
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                    connectionstring = null;
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 7
0
        /*
         * This is the event handler that removes the selected student from the database.  It requires
         * secondary authentication as an added precaution as it does modify the database.
         */
        private void removeButton_Click(object sender, EventArgs e)
        {
            if (studentListBox.SelectedIndex != -1)
            {
                using (var myform = new AdminLogin())
                {
                    //myform.ShowDialog();
                    //if (myform.DialogResult == DialogResult.OK && (myform.authok == "Admin" || myform.authok == "Administrator"))
                    //{
                    string   name      = studentListBox.SelectedItem.ToString();
                    string[] fullname  = name.Split(',');                       //tokenizes name for searching the DB
                    string   lastname  = fullname[0].Trim();
                    string   firstname = fullname[1].Trim();
                    string   password  = fullname[2].Trim();
                    Valid    student   = new Valid(lastname, firstname, Utility.Encrypt(password, false));
                    if (student.RemoveStudent(student))     //executes the remove SQL query and returns a boolean if successful
                    {
                        MessageBox.Show("Student removed.");
                        OpenFill();
                    }
                    else
                    {
                        MessageBox.Show("Error removing student.");
                    }
                    //}

                    /*else
                     * {
                     *  MessageBox.Show("Failed to remove student.");
                     * }*/
                }
            }
        }
Esempio n. 8
0
        /*
         * The primary function of this form, this button performs validation checking on user input
         * and queries the student DB for a password to match
         * It creates tokens for the name to pass into Valid class search functions and calls both
         * the Valid.Auth function for this purpose and also the Append function built into this form to
         * add an entry to the log file matching the current date
         * Upon login this also plays a system sound to notify lab assistant of a valid login and
         * reiterates the lab policies on display in the lab
         */
        private void button1_Click(object sender, EventArgs e)  //Validates student input and logs them in
        {
            try
            {
                if ((nameListBox.SelectedIndex != -1) && (passBox.Text.Length == 7)) //collects a name from the list box
                {                                                                    //and password from textbox
                    if (labRadio.Checked == true || tutorRadio.Checked == true || workRadio.Checked == true)
                    {
                        string   name      = nameListBox.SelectedItem.ToString();
                        string[] fullname  = name.Split(',');                   //tokenizes name for searching the DB
                        string   lastname  = fullname[0].Trim();
                        string   firstname = fullname[1].Trim();
                        Valid    student   = new Valid(firstname, lastname, passBox.Text);
                        if (student.Auth(firstname, lastname, passBox.Text))    //executes DB query to match passwords
                        {
                            //create/append a log file with name, ID, major and timestamp
                            //add to a list for the logout page
                            if (AppendLog(student, "Time in: "))
                            {
                                currentLogins.Add(name);
                                System.Media.SystemSounds.Asterisk.Play();      //system sound for lab assistants
                                Form policy = new LabPolicy();
                                policy.ShowDialog();
                                MessageBox.Show("Login successful.");

                                /*
                                 * MessageBox.Show("\t    LAB POLICIES: \n " +         //displays lab policies on login
                                 *  "No food or drink allowed in the lab. \n " +
                                 *  "No children allowed in the lab. \n " +
                                 *  "No vaping allowed in the lab. \n" +
                                 *  "10 page print limit per student per day.");*/
                                passBox.Clear();
                                majorBox.Clear();
                                textBox1.Focus();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Incorrect password.");
                            passBox.Clear();
                            passBox.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please choose why you are logging in today.");
                    }
                }
                else
                {
                    MessageBox.Show("Please select your name and enter your seven digit Student ID.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in Login button", ex.Message);
            }
        }
Esempio n. 9
0
 /*
  *      Method added to allow the mass importing of database objects.  This function has specific formatting requirements
  *      for its data files, requiring them to be in Last Name, First Name, StudentID order for correct entry into the database.
  *      A note appears in a message box when clicked, but is still contingent on correct user input.
  */
 private void importDatabaseObjectsToolStripMenuItem_Click_1(object sender, EventArgs e)
 {
     //message to user to inform of input requirements
     MessageBox.Show("When importing students, the file must be in a comma separated format." + Environment.NewLine +
                     "Students must be listed LastName,FirstName,StudentID." + Environment.NewLine +
                     "Student IDs of fewer than 7 characters will have 0s appended to the beginning to meet length requirements.");
     try
     {
         using (OpenFileDialog readFile = new OpenFileDialog())
         {
             readFile.Filter           = "txt files (*.txt)|*.txt|csv files (*.csv)|*.csv|xml files (*.xml)|*.xml";
             readFile.FilterIndex      = 2;
             readFile.RestoreDirectory = true; //restore directory to default after files are selected
             int counter = 0;                  //counter to track how many students are successfully added
             if (readFile.ShowDialog() == DialogResult.OK)
             {
                 using (StreamReader inputFile = new StreamReader(readFile.FileName))
                 {
                     while (!inputFile.EndOfStream)                                                             //loop the entirety of the file
                     {
                         string[] inputData = inputFile.ReadLine().Split(',');                                  //split each line, hence the comma requirement
                         if (inputData[2].Length <= 7 && int.TryParse(inputData[2], out int pass))              //check to see if the user ID meets DB requirements
                         {
                             while (inputData[2].Length < 7)                                                    //the DB requires user IDs to be 7 digits, as Excel trims beginning 0s we must add them
                             {
                                 inputData[2] = "0" + inputData[2];                                             //append 0s to the ID until it is 7 digits long
                             }
                             Valid student = new Valid(inputData[1].Trim(), inputData[0].Trim(), inputData[2]); //create the student, encryption is handled in the Valid class functions
                             if (!student.DupeCheck(student.Pass))                                              //check to see if the user is already in the DB
                             {
                                 student.InsertStudent(student);                                                //insert new students
                                 counter++;                                                                     //increment counter to track number of students added
                             }
                             else
                             {
                                 continue;
                             }
                         }
                         else
                         {
                             //Message box is displayed if the third value on each comma separated line is not a number
                             MessageBox.Show("An error has occured.  Failed to find a number for Student ID" +
                                             " or Student ID was greater than seven digits long.");
                         }
                     }
                     MessageBox.Show(counter.ToString() + " students imported successfully.");   //displays the student counter to compare against
                                                                                                 //expected number of students added
                 }
             }
         }
     }
     catch
     {
         MessageBox.Show("An error has occured while attempting to import students." + Environment.NewLine +
                         "Import process has been terminated.");
     }
 }
Esempio n. 10
0
        //Function to create an Administrator password if none exists
        private bool FirstTimeLoad()
        {
            Valid admin = new Valid();

            if (admin.Auth("Administrator", " "))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 11
0
        /*
         * This OpenFill method is functionally similar to the other listbox filling methods throughout
         * the forms, the key difference being this also populates the listbox with StudentIDs for
         * clarity in the removal process
         */
        private void OpenFill()  //populates the student list with the full database of students
        {
            studentListBox.Items.Clear();
            Valid         openFill     = new Valid();
            List <string> studentNames = new List <string>(openFill.StudentSearch("%", true));

            if (studentNames.Count > 0)
            {
                for (int i = 0; i < studentNames.Count; i++)
                {
                    string[] student = studentNames[i].Split(',');
                    studentListBox.Items.Add(student[0].Trim() + ", " + student[1].Trim() + ", " + Utility.Decrypt(student[2], false).Trim());
                }
            }
        }
Esempio n. 12
0
        private List <string> currentLogins = new List <string>();    //maintains a list of currently logged in students
                                                                      //would be nice if this wasn't global



        /*
         * This function returns the listbox to a full sorted list of all students in the database
         * Much like the other options that take advantage of Valid class SQL queries the
         * performance of this will depend on the student database being maintained as students
         * graduate
         */
        private void OpenFill()
        {
            nameListBox.Items.Clear();
            Valid         openFill     = new Valid();
            List <string> studentNames = new List <string>(openFill.StudentSearch("%"));

            studentNames.Sort();
            if (studentNames.Count > 0)
            {
                for (int i = 0; i < studentNames.Count; i++)
                {
                    nameListBox.Items.Add(studentNames[i]);
                }
            }
        }
Esempio n. 13
0
        /*
         * The following region is used to update the student name listbox for faster logins
         * It queries the database on text change to match users
         * The size of the DB could cause this function to run slowly if old users aren't pruned
         *
         * The first section is designed to escape apostrophes in user names to not interfere with
         * SQL queries
         * The try block uses a function of the Valid class to retrieve all student entries that
         * partial match the last name entered
         */
        #region ListBoxUpdater
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string name = textBox1.Text;

            if (name.Length == 0)
            {
                name = "%";
            }
            if (name.Length > 1)
            {
                if (name.Contains("'"))
                {
                    for (int i = 0; i < name.Length; i++)
                    {
                        if (name[i] == '\'')
                        {
                            name = name.Insert(i, "\'");
                            i++;
                        }
                    }
                }
            }
            else if (name.Length == 1 && name == "\'")
            {
                name += "'";
            }
            try
            {
                nameListBox.Items.Clear();
                Valid         students     = new Valid();
                List <string> studentNames = new List <string>(students.StudentSearch(name));
                studentNames.Sort();
                if (studentNames.Count > 0)
                {
                    for (int i = 0; i < studentNames.Count; i++)
                    {
                        nameListBox.Items.Add(studentNames[i]);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something is broken in the list fill.", ex.Message);
            }
            //nameListBox.BeginUpdate
        }
Esempio n. 14
0
        /*
         * This event handler filters the student list in the same way as the StudentLogin form
         * It carries the same restriction of only filtering by last name
         */
        private void searchBox_TextChanged(object sender, EventArgs e)
        {
            string name = searchBox.Text;

            if (name.Length == 0)   //sends a wildcard to the database for a full list when the search box is empty
            {
                name = "%";
            }
            if (name.Length > 1)    //escape sequence for names with apostrophes
            {
                if (name.Contains("'"))
                {
                    for (int i = 0; i < name.Length; i++)
                    {
                        if (name[i] == '\'')
                        {
                            name = name.Insert(i, "\'");
                            i++;
                        }
                    }
                }
            }
            else if (name.Length == 1 && name == "\'")
            {
                name += "'";
            }
            try
            {
                studentListBox.Items.Clear();
                Valid         students     = new Valid();
                List <string> studentNames = new List <string>(students.StudentSearch(name, true));
                if (studentNames.Count > 0)
                {
                    for (int i = 0; i < studentNames.Count; i++)
                    {
                        string[] student = studentNames[i].Split(',');
                        studentListBox.Items.Add(student[0].Trim() + ", " + student[1].Trim() + ", " + Utility.Decrypt(student[2], false).Trim());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something is broken in the list fill.", ex.Message);
            }
        }
Esempio n. 15
0
 /*
  * Function for creating new admin accounts.  Validates that all required fields have been filled on
  * button press and calls the appropriate Valid class function to insert
  */
 private void createButton_Click(object sender, EventArgs e)
 {
     if (createNameBox.Text != string.Empty)
     {
         if (createPassBox.Text != string.Empty && createConfirmBox.Text == createPassBox.Text)
         {
             string type;
             if (labRadioButton.Checked) //if statement to determine the account type being created
             {
                 type = "LabAssist";
             }
             else
             {
                 type = "Admin";
             }
             using (var myform = new AdminLogin())   //calls the AdminLogin form as an additional authorization
             {
                 myform.ShowDialog();
                 if (myform.DialogResult == DialogResult.OK && (myform.authok == "Admin" || myform.authok == "Administrator"))
                 {
                     Valid Admin = new Valid();
                     if (Admin.InsertAdmin(createNameBox.Text, createPassBox.Text, type))
                     {
                         MessageBox.Show("New user created.");
                     }
                     ListFill(true);
                     ListFill(false);
                 }
             }
         }
         else
         {
             MessageBox.Show("Password confirmation invalid.");
             ClearThings();
             createNameBox.Focus();
         }
     }
     else
     {
         MessageBox.Show("Please enter a name for this user.");
         ClearThings();
         createNameBox.Focus();
     }
 }
Esempio n. 16
0
        /*
         * This button to open the student logout form has been removed in favor or the function below it
         * which will allow students to log in and out from the same form.  The student logout form still
         * exists but is reserved for admin use.  Kept here for posterity.
         *
         * private void logoutButton_Click(object sender, EventArgs e)  //Alternative logout button to open the logout form
         * {                                                           //Created as a more user friendly alternative to menu item
         *  if (currentLogins.Count > 0)
         *  {
         *      using (var myform = new Logout(currentLogins))  //passes the current login list to the logout form
         *      {
         *          var result = myform.ShowDialog();
         *          if (result == DialogResult.OK)
         *          {
         *              currentLogins = myform.currentStudents; //receives an updated list from the logout form
         *          }
         *          OpenFill(); //repopulates the student login list
         *      }
         *  }
         *  else
         *  {
         *      MessageBox.Show("No students currently logged in.");
         *  }
         * }*/



        /*
         * The following button event handler is presented as an alternative to opening the student logout form using either
         * of the previous methods
         * Instead of calling the logout form this method reuses the existing code from the logout form to handle appending
         * the daily log and updating the currentlogin list
         * This method requires users to find their name in the list, requiring them to search or filter through the list in
         * the same way as when they log in, the example set by the previous login program required the use of a seperate form
         * to make searching the list for logouts faster, but the addition of a search box may obsolete the need for this form
         * This option is then presented as an alternative
         */
        private void button2_Click(object sender, EventArgs e)
        {
            if (currentLogins.Count > 0)
            {
                if (nameListBox.SelectedIndex != -1 && passBox.Text.Length == 7)
                {
                    string   name      = nameListBox.SelectedItem.ToString();
                    string[] fullname  = name.Split(',');                   //tokenizes name for searching the DB
                    string   lastname  = fullname[0].Trim();
                    string   firstname = fullname[1].Trim();
                    Valid    student   = new Valid(firstname, lastname, passBox.Text);
                    if (currentLogins.Contains(name))                        //ensures the student logging out is logged in
                    {
                        if (student.Auth(firstname, lastname, passBox.Text)) //executes DB query to match passwords
                        {
                            //create/append a log file with name, ID, major and timestamp
                            //add to a list for the logout page
                            if (AppendLog(student, "Time out: "))
                            {
                                MessageBox.Show("Logout successful.");
                                currentLogins.Remove(name);
                                passBox.Clear();
                                majorBox.Clear();
                                OpenFill();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("You are not currently logged in.");
                    }
                }
                else
                {
                    MessageBox.Show("Please select your name and enter your student ID.");
                }
            }
            else
            {
                MessageBox.Show("No students currently logged in.");
            }
        }
Esempio n. 17
0
 /*
  *  Method created to backup and scrub the database.  This is intended to be used each semester to allow administrators to import a current
  *  list of enrolled students.
  */
 private void backupAndDeleteDatabaseEntriesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MessageBox.Show("Warning, this will remove all entries from the student database.");
     try
     {
         createDatabaseDumpToolStripMenuItem.PerformClick();     //call the full DB dump function
         if (backedUp == true)                                   //check against form property set by the DB dump function
         {
             Valid student = new Valid("filler", "filler", "%"); //creates a student with a wildcard password for a full delete
             if (student.RemoveStudent(student))
             {
                 MessageBox.Show("Database has been backed up and scrubbed.");
             }
         }
     }
     catch
     {
         MessageBox.Show("An error has occured while performing the delete process.");
     }
 }
Esempio n. 18
0
        }                                   //creates a field we can return to the calling form

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Valid checking = new Valid();
                if (checking.Auth(nameBox.Text, passBox.Text) && passBox.Text.Length > 0) //Authentication for labassist/admins
                {
                    this.authok       = checking.Type(nameBox.Text, passBox.Text);        //Assigns the login type
                    this.DialogResult = DialogResult.OK;                                  //to the authok field
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Invalid username/password");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Problem with login form.");
            }
        }
Esempio n. 19
0
        /*
         * The following function is called from the Full Database Dump menu item, it retrieves the
         * entire student DB and creates a CSV file with it.  This module was created to aid in
         * determining which students need to be purged from the database.
         */
        private void createDatabaseDumpToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog saveFile = new SaveFileDialog();

                saveFile.Filter           = "txt files (*.txt)|*.txt|csv files (*.csv)|*.csv|xml files (*.xml)|*.xml";
                saveFile.FilterIndex      = 2;
                saveFile.RestoreDirectory = true;   //Should reset the directory when saving is finished.
                                                    //Maintaining the directory in other forms is still
                                                    //performed for reliability.
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    using (StreamWriter outputfile = new StreamWriter(saveFile.FileName))
                    {
                        //first line creates the header line for later importing the data
                        outputfile.WriteLine("Last Name, First Name, Student ID");

                        Valid         allStudents = new Valid();
                        List <string> fullDB      = new List <string>(allStudents.StudentSearch("%", true));

                        //cycle through the retrieved list and write each line as plain text
                        for (int i = 0; i < fullDB.Count; i++)
                        {
                            string[] logLine = fullDB[i].Split(',');
                            outputfile.WriteLine(logLine[0] + "," + logLine[1] + "," + Utility.Decrypt(logLine[2], false));          //writing each list item to file
                        }
                        allStudents = null;
                        fullDB      = null;
                        backedUp    = true;
                    }
                }
                saveFile = null;    //removes the save dialog from memory
            }
            catch
            {
                MessageBox.Show("Error exporting plain text log file.");
                backedUp = false;
            }
        }
Esempio n. 20
0
 /*
  * Function that manages updating passwords for the admin accounts.  This allows for the updating
  * of all accounts in the dbo.Admins, requiring the current password for security purposes.
  */
 private void updateButton_Click(object sender, EventArgs e)
 {
     if (updateListBox.SelectedIndex != -1)
     {
         if (oldPassBox.Text == string.Empty || updatePassBox.Text == string.Empty || confirmPassBox.Text == string.Empty)
         {
             MessageBox.Show("Please fill all password boxes.");
             ClearThings();
             oldPassBox.Focus();
         }
         else
         {
             Valid admin = new Valid();
             if (admin.Auth(updateListBox.SelectedItem.ToString(), oldPassBox.Text))
             {
                 if (admin.UpdateAdmin(updateListBox.SelectedItem.ToString(), updatePassBox.Text))
                 {
                     MessageBox.Show("Password update for " + updateListBox.SelectedItem.ToString() + " successful.");
                 }
             }
         }
     }
 }
Esempio n. 21
0
 //9/4/18 change, SQL statement from = to LIKE to support database scrubbing method in Forms.AdminTasks
 public bool RemoveStudent(Valid student)
 {
     try
     {
         string connectionstring = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Students.mdf;Integrated Security=True;Connect Timeout=30";
         using (SqlConnection sqlcon = new SqlConnection(connectionstring))
         {
             SqlParameter passParam  = new SqlParameter("@password", SqlDbType.NVarChar, 50);
             string       removename = "DELETE FROM dbo.Student WHERE Student.StudentID LIKE @password;";
             passParam.Value = student.Pass;
             SqlCommand cmd = new SqlCommand(removename, sqlcon);
             cmd.Parameters.Add(passParam);
             sqlcon.Open();
             cmd.Prepare();
             cmd.ExecuteNonQuery();
             connectionstring = null;
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 22
0
 /*
  * This function handles inserting the students into the dbo.Students.  It performs validation
  * of name/passwords then calls a SQL function to check for duplicates in the StudentID DB field,
  * then calls the insert SQL function to add the student to the dbo.Students.
  */
 private void addButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (firstBox.Text.Length > 0 && lastBox.Text.Length > 0)
         {
             /*
              * This section validates the name as password entry.  It creates boolean values
              * that are set to false if the text entered in either the first or last name box
              * contains a character other than a letter or apostrophe.  Current parameterization
              * in the SQL statements and forbidding the SQL comment character in name entry has so far
              * prevented injection and precluded the need for apostrophe escape sequencing
              */
             bool   validname = true;
             bool   validpass = false;
             string name      = firstBox.Text.Trim();
             foreach (char c in name)
             {
                 if (!char.IsLetter(c) && c != '\'') //verifies that the name is composed only of
                 {                                   //letters and apostrophe
                     validname = false;
                 }
             }
             if (!validname)
             {
                 MessageBox.Show("Please enter a valid first name.");
             }
             name = lastBox.Text.Trim();
             foreach (char c in name)
             {
                 if (!char.IsLetter(c) && c != '\'')
                 {
                     validname = false;
                 }
             }
             if (!validname)
             {
                 MessageBox.Show("Please enter a valid last name.");
             }
             if (passBox.Text.Length == 7)   //checks to ensure the password is exactly 7 characters
             {                               //can be adjusted based on current length of YT Student IDs
                 if (passBox.Text == confirmBox.Text)
                 {
                     string password = passBox.Text;
                     if (int.TryParse(password, out int temp))    //check password is a number
                     {
                         validpass = true;
                     }
                 }
             }
             if (!validpass)
             {
                 MessageBox.Show("Please enter your seven digit student ID");
                 passBox.Clear();
                 confirmBox.Clear();
                 passBox.Focus();
             }
             if (validname && validpass)
             {
                 Valid student = new Valid(firstBox.Text, lastBox.Text, passBox.Text);
                 //perform a check for duplicate Student IDs
                 if (student.DupeCheck(passBox.Text))
                 {
                     MessageBox.Show("Duplicate Student ID entry detected.");
                 }
                 else if (student.InsertStudent(student))    //attempts to insert new student
                 {
                     MessageBox.Show("Student added.");
                 }
                 else
                 {
                     MessageBox.Show("Failed to add student.");
                 }
                 //clear and reset boxes to allow for multiple student entry
                 //can be changed to a simple .Close statement if one entry per form load is preferred
                 firstBox.Clear();
                 lastBox.Clear();
                 passBox.Clear();
                 confirmBox.Clear();
                 firstBox.Focus();
             }
         }
     }
     catch
     {
         MessageBox.Show("Failed to add student.");
     }
 }
Esempio n. 23
0
 /*
  * This module creates a date time and an entry string for logging purposes, then adds
  * an entry to a log file based on the current date and creates that file if it does not already exist
  *
  */
 private bool AppendLog(Valid student, string inout)  //Will append a log file of the current date with student name
 {
     try
     {
         string major, reason;
         if (majorBox.Text.Length > 0)
         {
             major = majorBox.Text;
             if (major.Contains(","))
             {
                 for (int i = 0; i < major.Length; i++)
                 {
                     if (major[i] == ',')
                     {
                         major = major.Remove(i, 1);
                         i--;
                     }
                 }
             }
         }
         else
         {
             major = "unspecified";      //major is an optional entry this is provided for
         }                               //spacing reasons in the log viewer
         if (labRadio.Checked)
         {
             reason = "Outside lab";
         }
         else if (tutorRadio.Checked)
         {
             reason = "Tutoring";
         }
         else
         {
             reason = "Class/Homework";
         }
         labRadio.Checked   = false;
         tutorRadio.Checked = false;
         workRadio.Checked  = false;
         string   logDir    = Path.Combine(Environment.CurrentDirectory, "Logs");
         DateTime dt        = DateTime.Now;
         string   date      = dt.ToShortDateString();
         string   time      = dt.ToShortTimeString();
         string[] newdate   = (dt.Date.ToString()).Split();
         string[] dateparts = newdate[0].Split('/');
         date = dateparts[0] + "-" + dateparts[1] + "-" + dateparts[2];
         if (!Directory.Exists(logDir))
         {
             Directory.CreateDirectory(logDir);
         }
         string logpath = date + ".txt";
         using (StreamWriter outputfile = new StreamWriter("Logs\\" + logpath, true))
         {
             string encryptText = Utility.Encrypt(student.First + "," + student.Last + "," + student.Pass + "," + date + "," + inout + ',' + time + "," + major + "," + reason, false);
             outputfile.WriteLine(encryptText);
             outputfile.Close();
             return(true);
         }
     }
     catch
     {
         MessageBox.Show("Error writing to log.");
     }
     return(false);
 }