Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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.");
            }
        }
Ejemplo n.º 4
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.");
            }
        }
Ejemplo n.º 5
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.");
                 }
             }
         }
     }
 }