コード例 #1
0
        /// <summary>
        /// Generates a set password with random numerics and characters.
        /// </summary>
        /// <returns>The password.</returns>
        public PasswordInfo GeneratePasswordInfo(string site)
        {
            var info = FileSystem.ReadFromFile(site);

            if (info != null)
            {
                var modifiedInfo = new PasswordInfo
                {
                    Site          = site,
                    Password      = GeneratePassword(),
                    Creation_Date = info.Creation_Date,
                    Changed_Date  = DateTime.Now,
                    Has_Changed   = true
                };

                return(modifiedInfo);
            }

            var newInfo = new PasswordInfo
            {
                Site          = site,
                Password      = GeneratePassword(),
                Creation_Date = DateTime.Now,
                Changed_Date  = new DateTime(1111, 11, 1, 11, 11, 11),
                Has_Changed   = false
            };

            return(newInfo);
        }
コード例 #2
0
        /// <summary>
        /// Writes the provided password object to a json file.
        /// </summary>
        /// <param name="info">Info.</param>
        public static void WriteToFile(PasswordInfo info)
        {
            string relativePath = @"Resources";
            string filePath     = GetFilePath(info.Site);

            if (!Directory.Exists(relativePath))
            {
                Directory.CreateDirectory(relativePath);
            }

            string content = JsonConvert.SerializeObject(info, Formatting.Indented);

            using (StreamWriter sw = File.CreateText(filePath))
            {
                sw.Write(content);
            }
        }
コード例 #3
0
        void GetNewPassword(string site)
        {
            Console.WriteLine("\nGenerating a new password...");
            PasswordInfo info = _PasswordGenerator.GeneratePasswordInfo(site);

            if (info != null)
            {
                Console.WriteLine("Site: " + info.Site + "\nNew Password: "******"Sorry! An error occured, please try again.");
            }

            FileSystem.WriteToFile(info);
            EndProgram();
        }
コード例 #4
0
        void ReadPassword()
        {
            string site = GetSite();

            Console.WriteLine("\nRetrieving password...");
            PasswordInfo info = FileSystem.ReadFromFile(site);

            if (info == null)
            {
                Console.WriteLine("There is no password for that site.");
            }
            else
            {
                Console.WriteLine("Site: " + info.Site + "\nNew Password: "******"\nCreated at: " + info.Creation_Date);
            }

            EndProgram();
        }