// Read a user public Common.clsUser Read(Common.clsLogInData objLogin) { Common.clsUser objUsers = new Common.clsUser(); try { // Query to read a voter string QueryString = string.Format(@"select Username, Passwords, UserType from users where Username = '******' and Passwords = '{1}' and UserType = '{2}'", objLogin.Username, objLogin.Password, objLogin.UserType); using (SqlConnection Connection = new SqlConnection(clsConnectingDA.ConnectionString)) { using (SqlCommand Command = Connection.CreateCommand()) { // Load Query Command.CommandText = QueryString; // Open connection Connection.Open(); // Execute query using (SqlDataReader reader = Command.ExecuteReader()) { if (reader.Read()) { objUsers.Username = (string)reader["Username"]; objUsers.Password = (string)reader["Passwords"]; objUsers.UserType = (string)reader["UserType"]; } } // Close connection Connection.Close(); } } } catch (Exception) { } return(objUsers); }
// Login public Common.clsUser Login(Common.clsLogInData objLogIn) { // Read voter Data.clsUserDA objUserSystemDA = new Data.clsUserDA(); var objUserSystem = objUserSystemDA.Read(objLogIn); if (objUserSystem.Username is null) { throw new Exception("Invalid Login!"); } if (!objLogIn.UserType.Equals(objUserSystem.UserType) || !objLogIn.Username.Equals(objUserSystem.Username) || !objLogIn.Password.Equals(objUserSystem.Password)) { throw new Exception("Invalid Login!"); } return(objUserSystem); }