Inheritance: ICredentials
        public Credentials Load()
        {
            Credentials credentials = new Credentials();
            using (var reader = new StreamReader(StorageFile.OpenFile(Common.CredentialsFile, FileMode.OpenOrCreate, FileAccess.Read)))
            {
                bool isEncrypted;
                IsolatedStorageSettings.ApplicationSettings.TryGetValue("IsEncrypted", out isEncrypted);
                if (reader.Peek() > 0)
                {
                    try
                    {
                        credentials.Email = isEncrypted ? _crypto.Decrypt(reader.ReadLine()) : reader.ReadLine();
                        credentials.Password = isEncrypted ? _crypto.Decrypt(reader.ReadLine()) : reader.ReadLine();
                        credentials.Game = (SupportedGame) Convert.ToInt32(reader.ReadLine());
                        credentials.RememberMe = !string.IsNullOrEmpty(credentials.Password) && Convert.ToBoolean(reader.ReadLine());
                    }
                    catch (Exception e)
                    {
                        // If it's format exception, then user has not saved credentials in new format before
                        if (!(e is FormatException))
                            throw;
                    }
                }
            }

            if (credentials.Email == null || credentials.Password == null || credentials.Password.Length > 20)
                return new Credentials();
            return credentials;
        }
 public void LoadAndSaveTest()
 {
     var repository = new FileCredentialsRepository(IsolatedStorageFile.GetUserStoreForApplication());
     var expected = new Credentials()
         {
             Email = "*****@*****.**",
             Password = "******",
             RememberMe = true
         };
     repository.Save(expected);
     var actual = repository.Load();
     Assert.IsTrue(expected.Equals(actual));
 }
 public void Save(Credentials credentials)
 {
     using (var writer = new StreamWriter(StorageFile.OpenFile(Common.CredentialsFile, FileMode.Create, FileAccess.Write)))
     {
         //writer.WriteLine(_crypto.Encrypt(credentials.Email));
         //writer.WriteLine(_crypto.Encrypt(credentials.Password));
         writer.WriteLine(credentials.Email);
         writer.WriteLine(credentials.Password);
         writer.WriteLine((int)credentials.Game);
         writer.WriteLine(credentials.RememberMe);
     }
     IsolatedStorageSettings.ApplicationSettings["IsEncrypted"] = false;
 }
        public ICredentials Load()
        {
            ICredentials credentials = new Credentials();
            using (var reader = new StreamReader(StorageFile.OpenFile(Common.CredentialsFile, FileMode.OpenOrCreate, FileAccess.Read)))
            {
                bool isEncrypted;
                IsolatedStorageSettings.ApplicationSettings.TryGetValue("IsEncrypted", out isEncrypted);
                if (reader.Peek() > 0)
                {
                    credentials.Email = isEncrypted ? _crypto.Decrypt(reader.ReadLine()) : reader.ReadLine();
                    credentials.Password = isEncrypted ? _crypto.Decrypt(reader.ReadLine()) : reader.ReadLine();
                    credentials.RememberMe = !string.IsNullOrEmpty(credentials.Password) && Convert.ToBoolean(reader.ReadLine());
                }
                reader.Close();
            }

            if (credentials.Email == null || credentials.Password == null || credentials.Password.Length > 20)
                return new Credentials();
            return credentials;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Save credentials to phone
 /// </summary>
 private void SaveCredentials()
 {
     Credentials credentials = new Credentials();
     if (RememberMe)
     {
         credentials.Email = Email;
         credentials.Password = Password;
         credentials.Game = Game;
         credentials.RememberMe = RememberMe;
     }
     CredentialsRepository.Save(credentials);
 }