private void LoadAuth(IsolatedStorageFile isoStore) { if (isoStore.FileExists(AuthFilename)) { try { using (var stream = isoStore.OpenFile(AuthFilename, FileMode.Open, FileAccess.Read)) using (var br = new BinaryReader(stream)) { var fileVer = br.ReadInt32(); var unameLen = br.ReadInt32(); var unameEncrypted = br.ReadBytes(unameLen); var pwordLen = br.ReadInt32(); var pwordEncrypted = br.ReadBytes(pwordLen); var unamePlain = ProtectedData.Unprotect(unameEncrypted, null); var pwordPlain = ProtectedData.Unprotect(pwordEncrypted, null); _username = System.Text.Encoding.UTF8.GetString(unamePlain, 0, unamePlain.Length); _password = System.Text.Encoding.UTF8.GetString(pwordPlain, 0, pwordPlain.Length); IsAuthenticated = true; InitAuth(_username, _password); var numContexts = br.ReadInt32(); Contexts.Clear(); for (int i = 0; i < numContexts; i++) { var usr = new User(); usr.Load(br, fileVer); Contexts.Add(new Context() { User = usr }); } AuthenticatedUser = Contexts[0].User; br.Close(); } } catch (EndOfStreamException) { isoStore.DeleteFile(AuthFilename); } } else { IsAuthenticated = false; } }
public void Login(string username, string password) { githubRepository.Login(username, password); User = githubRepository.GetUser().Result; }