Esempio n. 1
0
        /// <summary>
        /// Validate login username & password
        /// </summary>
        /// <param name="enteredUsername">string</param>
        /// <param name="enteredPassword">string</param>
        /// <returns>Boolean if it was successful or not</returns>
        private Boolean ValidLoginUserPassword(string enteredUsername, string enteredPassword)
        {
            Boolean      isValid      = false;
            List <Users> currentUsers = GetUsers();

            foreach (Users user in currentUsers)
            {
                if (CompareStrings(enteredUsername, user.Username, true))
                {
                    string username            = user.Username;
                    string encryptedPassword   = user.Password; // encrypted password
                    string unencryptedPassword = PasswordEncryption.Decrypt(encryptedPassword, username);

                    if (CompareStrings(enteredPassword, unencryptedPassword, false))
                    {
                        isValid = true;
                    }
                }
            }

            return(isValid);
        }
Esempio n. 2
0
        /// <summary>
        /// Processes user input to create new user account
        /// </summary>
        private void CreateAccount()
        {
            string  tempUser        = "";
            string  newUser         = "";
            string  tempPassword    = "";
            string  newPassword     = "";
            Boolean exit            = false;
            Boolean isValidUser     = false;
            Boolean isValidPassword = false;

            cw("Creating a new user account.");
            while (!exit)
            {
                cw("Please enter new username or type 'exit' to go back to the main menu.");
                while (!isValidUser)
                {
                    tempUser = ""; // ensuring var is cleared before re-assignment
                    newUser  = "";

                    tempUser = GetInput();

                    if (tempUser != "")
                    {
                        if (!ToExit(tempUser))
                        {
                            Boolean usernameSuccess = CheckUsername(tempUser);
                            if (usernameSuccess == true)
                            {
                                newUser     = tempUser.ToLower(); // ensures username will always be stored as a lower - ensure passphrase success on decryption
                                isValidUser = true;
                                break;
                            }
                        }
                        else
                        {
                            exit = true;
                            break;
                        }
                    }
                    else
                    {
                        cw("Username entered was blank. Please enter a valid username.");
                    }
                }

                if (exit == true) // check for exit break
                {
                    break;
                }

                cw("Please enter new password or type 'exit to go back to the main menu.");
                while (!isValidPassword)
                {
                    tempPassword = "";// ensuring var is cleared before re-assignment
                    newPassword  = "";

                    tempPassword = GetInput();
                    if (tempPassword != "")
                    {
                        if (!ToExit(tempPassword))
                        {
                            Boolean passwordSuccess = CheckPassword(tempPassword);
                            if (passwordSuccess == true)
                            {
                                newPassword     = PasswordEncryption.Encrypt(tempPassword, newUser); // Password encryption
                                isValidPassword = true;
                                break;
                            }
                        }
                        else
                        {
                            exit = true;
                            break;
                        }
                    }
                    else
                    {
                        cw("Password entered was blank. Please enter a valid password.");
                    }
                }

                if (exit == true) // check for exit break
                {
                    break;
                }

                if (isValidUser && isValidPassword)
                {
                    exit = CreateAccount(newUser, newPassword);
                    if (exit == true)
                    {
                        cw("New user has been added. Returning to main menu.");
                    }
                    else
                    {
                        cw("There was an Error adding the new user. Please try again.");
                    }
                }
            }
        }