/// <summary> /// Load credentials from the config file /// </summary> public static string[] LoadCredentials() { try { var user = new User { Email = "", Password = "" }; var credentialFile = Directory + "credentials.config"; if (!System.IO.File.Exists(credentialFile)) { System.IO.File.WriteAllText(credentialFile, JsonConvert.SerializeObject(user)); } var userData = System.IO.File.ReadAllText(credentialFile); var jsonUser = JsonConvert.DeserializeAnonymousType(userData, user); Email = Encrypter.DecryptString(jsonUser.Email); Password = Encrypter.DecryptString(jsonUser.Password); } catch { Email = ""; Password = ""; } string[] credentials = { Email, Password }; return credentials; }
/// <summary> /// Save encrypted username and password to the config /// </summary> public static void SaveCredentials(string email, string password) { var user = new User { Email = Encrypter.EncryptString(email), Password = Encrypter.EncryptString(password) }; var jsonUser = JsonConvert.SerializeObject(user); System.IO.File.WriteAllText(Directory + "credentials.config", jsonUser); //Save Local Copy: Email = email; Password = password; }