//This method checks to see if password and username input from each textbox matches password and username data stored in the LecturerLogin table of the application database. public void LoginLecturer() { ModelRegisterLogin lect = new ModelRegisterLogin(); //Generic collections List <T> is used to hold all the lecturer login details for processing. The list is instantiated using a method that retrieves all the login details from the application database, LecturerLogin. List <ModelRegisterLogin> list = cl.GetAllFromLecturerLogin(connectionString); //A lambda expression combined with a try catch is used to determines if the users username input taken from the login texbox matchs any username objects of the Model Class ModelRegisterLogin - this Model Class holds properties for both the lecturer and student user types. try { lect = list.Find((ModelRegisterLogin x) => x.LECT_USERNAME == Int32.Parse(tbUsernameLog.Text)); //The lambda expression above checks if any dataabase username data matches the user input from the username texbox. if (lect.LECT_USERNAME.ToString().Equals(tbUsernameLog.Text) && lect.LECT_PASSWORD.ToString().Equals(tbPasswordLog.Password)) { MessageBox.Show("Login Successful !\nWelcome LECTURER " + lect.LECT_USERNAME.ToString()); ; MainMenuLecturer mml = new MainMenuLecturer(Int32.Parse(tbUsernameLog.Text)); mml.Show(); this.Close(); } else { //if a username is found but the password doesnt match then this message will be displayed to the user MessageBox.Show("Incorrect username or password\nPlease recheck your credentials and try again", "Error"); tbUsernameLog.Text = ""; tbPasswordLog.Password = ""; } } catch (System.Exception) { //If no username match is found the application will throw an error which indicates that no such data with in the database matches that of the user data. //If this is so then the application displays the following message. MessageBox.Show("Incorrect username or password\nPlease recheck your credentials and try again", "Error"); tbUsernameLog.Text = ""; tbPasswordLog.Password = ""; } }
public void LoginLecturer() { ModelRegisterLogin lect = new ModelRegisterLogin(); List <ModelRegisterLogin> list = cl.GetAllFromLecturerLogin(connectionString); try { lect = list.Find((ModelRegisterLogin x) => x.LECT_USERNAME == tbUsernameLog.Text); if (lect.LECT_USERNAME.ToString().Equals(tbUsernameLog.Text) && lect.LECT_PASSWORD.ToString().Equals(tbPasswordLog.Password)) { MessageBox.Show("Login Successful !,\n Welcome LECTURER " + lect.LECT_USERNAME.ToString()); MainMenuLecturer mml = new MainMenuLecturer(); mml.Show(); this.Close(); } else { MessageBox.Show("Incorrect username or password\nPlease recheck your credentials and try again", "Error"); tbUsernameLog.Text = ""; tbPasswordLog.Password = ""; } } catch (System.Exception) { MessageBox.Show("Incorrect username or password\nPlease recheck your credentials and try again", "Error"); tbUsernameLog.Text = ""; tbPasswordLog.Password = ""; } }