/// <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); }
/// <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); } }
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(); }
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(); }