private static void Login(Stream outstream, string[] args, bool loggingIn) { for (int i = 0; i < args.Length; i++) { args[i] = args[i].Trim(); } Account account = null; if (loggingIn) { account = AccountMapper.ReadAccountByUserPass(args[0], args[1]); } else { // Make sure the student exists if (int.TryParse(args[2], out int id) && StudentMapper.ReadStudentByID(id) != null && AccountMapper.ReadAccountByUserPass(args[0], args[1]) == null) { account = new Account() { Username = args[0], Password = args[1], StudentID = id }; AccountMapper.CreateAccount(account); } } using (StreamWriter _out = new StreamWriter(outstream)) { try { if (account == null) { _out.WriteLine("FAIL"); } else if (account.StudentID == null) { _out.WriteLine("ADMIN"); } else { _out.WriteLine("STUDENT"); } // _out.Flush(); } catch (ObjectDisposedException) { } } }
static void Main() { //Notes(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); LoginForm login = new LoginForm(); for ( DialogResult result = login.ShowDialog(); result != DialogResult.Cancel; result = login.ShowDialog() ) // I suppose this is a tad unconventional, but w/e { if (result == DialogResult.OK) { Account account = AccountMapper.ReadAccountByUserPass(login.Username, login.Password); if (account == null) { MessageBox.Show("Invalid username or password", "Login Error"); } else if (account.StudentID == null) { Application.Run(new AdminForm(account.AccountID)); } else { Application.Run(new StudentsReservations(account.AccountID)); } } else // result == DialogResult.Ignore { if (int.TryParse(login.StudentID, out int id) && StudentMapper.ReadStudentByID(id) != null && AccountMapper.ReadAccountByUserPass(login.Username, login.Password) == null) { AccountMapper.CreateAccount(new Account() { Username = login.Username, Password = login.Password, StudentID = id }); login.ClearInfo(true); } else { MessageBox.Show("Invalid student ID or username already taken", "Login Error"); } } } }