public void UpdateLoginDatabase(Staff newStaff)
        {
            LoginDatabase loginDB       = new LoginDatabase();
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(LoginDatabase));

            using (StreamReader reader = new StreamReader("loginDetails.xml"))
            {
                loginDB = (LoginDatabase)xmlSerializer.Deserialize(reader);
            }

            LoginDatabase newLoginDB = new LoginDatabase();

            if (loginDB.getExistingUsers().Count != 0 && loginDB.getExistingUsers()[0].getUsername() == "admin")
            {
                newLoginDB.AddUser(loginDB.getExistingUsers()[0]);
            }
            else
            {
                newLoginDB.createAdminAccount();
            }

            foreach (Staff staff in DB.GetListOfStaffMembers())
            {
                bool staffAdded = false;
                foreach (Session user in loginDB.getExistingUsers())
                {
                    if (staff.getPersonID() == user.getUserID() && !staffAdded)
                    {
                        string username = staff.getFirstName() + "." + staff.getSurname() + staff.getPersonID().ToString();
                        if (username != user.getUsername())
                        {
                            user.setUsername(username);
                            user.changePassword("password");
                        }
                        newLoginDB.AddUser(user);
                        staffAdded = true;
                    }
                }
            }

            Session newUser = new Session(newStaff);

            newLoginDB.AddUser(newUser);

            using (TextWriter writer = new StreamWriter("loginDetails.xml"))
            {
                xmlSerializer.Serialize(writer, newLoginDB);
            }
        }
Example #2
0
        public void LoginSystem()
        {
            string  inputUsername = textBoxUsername.Text;
            string  inputPassword = passwordBoxPassword.Password;
            Session userToCheck   = null;

            foreach (Session session in loginDB.getExistingUsers())
            {
                if (session.getUsername() == inputUsername)
                {
                    userToCheck = session;
                }
            }

            if (userToCheck == null)
            {
                MessageBox.Show("User does not exist");
            }
            else if (userToCheck.getPassword() != inputPassword)
            {
                MessageBox.Show("Wrong password");
            }
            else
            {
                currentSession = userToCheck; DB.SetCurrentSession(currentSession); Content = new MainMenu(DB);
            }
        }
Example #3
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            CheckData();
            if (oldPassOK && newPassOK && newPassConfirmOK)
            {
                DB.GetCurrentSession().changePassword(NewPassTextBox.Password);
                LoginDatabase loginDB       = new LoginDatabase();
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(LoginDatabase));
                using (StreamReader reader = new StreamReader("loginDetails.xml"))
                {
                    loginDB = (LoginDatabase)xmlSerializer.Deserialize(reader);
                }

                foreach (Session user in loginDB.getExistingUsers())
                {
                    if (DB.GetCurrentSession().getUserID() == user.getUserID())
                    {
                        user.changePassword(NewPassTextBox.Password);
                    }
                }

                using (TextWriter writer = new StreamWriter("loginDetails.xml"))
                {
                    xmlSerializer.Serialize(writer, loginDB);
                }

                DialogResult = true;
                this.Close();
            }
        }