示例#1
0
        /// <summary>
        /// Per assignment requirements:
        /// Opens the output file and writes the user's name along with the result of
        /// adding the two integer values and the result of multiplying the two integer values,
        /// followed by the contents of the input file
        /// </summary>
        private static void OutputToFile()
        {
            try
            {
                FileController.WriteToFile(
                    _fileOutputName,
                    _name + " " + "Added: " + _numOne + " Muliplied: " + _numTwo + "\n",
                    string.Empty,
                    true,
                    false);

                StreamReader reader = new StreamReader(Path.GetFullPath(_fileInputName), System.Text.Encoding.UTF8, true, 512);
                StreamWriter writer = new StreamWriter(Path.GetFullPath(_fileOutputName), append: true);

                string line;

                while ((line = reader.ReadLine()) != null)

                {
                    writer.WriteLine(line);
                }

                reader.Close();
                writer.Close();
            }
            catch (Exception e)
            {
                ErrorLogFile(
                    $"Warning: An Error occured during the FileInAndOut method at {DateTime.Now}\n" + e.Message);
            }
        }
示例#2
0
        private static void UserInputPassword()
        {
            string prompt = "Enter a password between 8 and 24 characters, with no spaces, only alphanumeric characters, and the following special characters: ! @ % ^ & *" +
                            "\r\nThe password must contain at least one uppercase letter, one lowercase letter, one number, and one special character.";


            //SHA256 sha256 = SHA256.Create();
            RNGCryptoServiceProvider rngProvider = new RNGCryptoServiceProvider();

            byte[] salt = new byte[32];
            rngProvider.GetNonZeroBytes(salt);

            FileController.WriteToFile(".password.ini", GetHashSHA256(GetUserInput(prompt, _passwordPatternRegex), salt) + "\n" + Convert.ToBase64String(salt), append: false, hidden: true, noWrite: true, encrypted: true);

            bool valid = ValidatePassword(GetUserInput("Repeat Password: "******"Password was not correct.");

                valid = ValidatePassword(GetUserInput("Repeat Password: "******"Password was correct.");
        }