public LoginController(ref int userAcctType, string user, string pass)
        {
            fail = false;

            Database_Manager dbMngr = new Database_Manager();

            if (dbMngr.checkUsername(user))
            {
                //checks the db password against the salted version of the provided password
                string dbPass   = dbMngr.FetchPassword(user);
                string saltPass = (pass + ".cs.is.fun.team.dirk.");
                string hashPass = Convert.ToString(saltPass.GetHashCode());
                if (dbPass != (hashPass))
                {
                    MessageBox.Show("Your password was not correct. Please enter the right credentials.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    fail = true;
                }
                else
                {
                    //Check user's account type
                    string type = dbMngr.Fetchaccttype(user);
                    Console.WriteLine(type);
                    if (type == "Administrator")
                    {
                        userAcctType = 3;
                    }
                    else if (type == "Researcher")
                    {
                        userAcctType = 2;
                    }
                    else if (type == "Student")
                    {
                        userAcctType = 1;
                    }

                    //Proceed to Main Menu
                    //new MainMenu(userAcctType).Show();
                }
            }
            else
            {
                MessageBox.Show("Your username was not correct. Please enter the right credentials.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                fail = true;
            }
        }
예제 #2
0
        public void Main(string first, string last, string username, string password, string accType)
        {
            Database_Manager db     = new Database_Manager();
            bool             exists = false;

            exists = db.checkUsername(username);
            if (exists)
            {
                if (password != null && password != "")
                {
                    // salt and hash the password
                    password = Salt(password);
                    int hashPass = Hash(password);
                    password = Convert.ToString(hashPass);
                    db.ChangePassword(username, password);
                }
                if (last != null && last != "")
                {
                    db.ChangeLastname(username, last);
                }
                if (first != null && first != "")
                {
                    db.ChangeFirstname(username, first);
                }
                if (accType != null && accType != "" && accType != "(No change)")
                {
                    db.ChangeAccType(username, accType);
                }
                if (verify(username, password, first, last, accType))
                {
                    MessageBox.Show("User account successfully changed.");
                }
                else
                {
                    MessageBox.Show("ERROR: User info was not changed");
                }
            }
            else
            {
                MessageBox.Show("ERROR: User account does not exist");
            }
        }
예제 #3
0
        // main driver for addUser logic
        public void main(string first, string last, string username, string password, string accType, string file)
        {
            Database_Manager dbm = new Database_Manager();
            string           msg = "";
            int    addedCount    = 0;
            int    failedCount   = 0;
            bool   valid;
            bool   added  = false;
            bool   exists = true;
            string line;

            // entries from a batch file
            if (file != "")
            {
                // while not at the end of the csv file, read the line and save the data in the corresponding variables
                using (StreamReader sr = File.OpenText(file))
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] values = new string[5] {
                            "", "", "", "", ""
                        };                                                     // sets initial values to 0
                        string[] tempValues = line.Split(',');                 // creates a temp array, so if something is missing, it doesnt mess up assigning values below
                        for (int i = 0; i < tempValues.Length; i++)
                        {
                            values[i] = tempValues[i];
                        }
                        // set values
                        first    = values[0];
                        last     = values[1];
                        username = values[2];
                        password = values[3];
                        accType  = values[4];
                        // verify that required info is provided
                        failedItems = new string[5];
                        valid       = verifyInfo(first, last, username, password, accType);
                        // if it is
                        if (valid == true)
                        {
                            // check database to see if username exists
                            exists = dbm.checkUsername(username);
                            if (exists == false)
                            {
                                // salt and hash pasword
                                password = Salt(password);
                                int hashPass = Hash(password);
                                password = Convert.ToString(hashPass);
                                // add to database
                                added = dbm.addUser(first, last, username, password, accType);
                                // if the user was added, keep track of the addition
                                if (added == true)
                                {
                                    // user was added, update added info
                                    addedCount = updateAddedCount(addedCount);
                                    addedUserList.Add(first + " " + last + ": " + username);
                                }
                                else
                                {
                                    // user was not added, update failed info
                                    failedCount = updateFailedCount(failedCount);
                                    failedUserList.Add(first + " " + last + ": " + username);
                                }
                            }
                            else
                            {
                                // username already exists in DB
                                failedCount = updateFailedCount(failedCount);
                                failedUserList.Add(first + " " + last + ": " + username);
                            }
                        }
                        else
                        {
                            // if user was not added, keep track of failed additions
                            failedCount = updateFailedCount(failedCount);
                            failedUserList.Add(first + " " + last + ": " + username);
                        }
                    }
                    // create a message of how many added and failed users from batch file
                }
                msg = createBatchMsg(addedCount, failedCount);
                // empty the lists so the next batch file the admin uses doesnt have this files info in it
                addedUserList.Clear();
                failedUserList.Clear();
            }

            // used for text box entries
            else
            {
                // verify that required info is provided
                failedItems = new string[5];
                valid       = verifyInfo(first, last, username, password, accType);
                // if it is
                if (valid == true)
                {
                    // check database to see if username exists
                    exists = dbm.checkUsername(username);
                    if (exists == false)
                    {
                        // salt and hash pasword
                        password = Salt(password);
                        int hashPass = Hash(password);
                        password = Convert.ToString(hashPass);
                        // add to database
                        added = dbm.addUser(first, last, username, password, accType);
                        if (added == true)
                        {
                            // provide confirmation
                            msg = confirmMsg(username);
                        }
                        else
                        {
                            // this message is when the catch is called in the database
                            msg = "Error while adding user, can not use username: " + username;
                        }
                    }
                    else
                    {
                        msg = userExistsMsg(username);
                    }
                }
                else
                {
                    // provide feedback why it didn't get added
                    msg = failMsg(username);
                }
            }
            // display success/fail message
            ShowMsg(msg);
        }