/// <summary> /// Check for existing wifi profile in the cache. If a WiFi profile exits, automatically connects /// to that WiFi AP. /// </summary> private async Task CheckWifiSetting() { try { var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.RetrieveAll(); if (credentialList?.Count > 0) { Log("Connecting to stored Wifi Profile..."); var credential = credentialList[0]; await m_wiFiManager.Initialize(); credential.RetrievePassword(); WiFiConnectionStatus status = await m_wiFiManager.Connect(credential.UserName, credential.Password); if (status == WiFiConnectionStatus.Success) { Log("Connected to AP " + credential.UserName + "."); return; } Log("Failed to connected to AP " + credential.UserName + "."); } m_chatServer.StartListening(); m_bluetoothManager.StartWatcher(); } catch (Exception e) { Log("CheckWifiSetting::[ERROR]" + e.Message); } return; }
protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args) { var rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; Window.Current.Content = rootFrame; Window.Current.Activate(); var op = args.ShareOperation; var credentialVault = new Windows.Security.Credentials.PasswordVault(); var credentialList = credentialVault.RetrieveAll(); if (credentialList.Count > 0) { var credential = credentialVault.Retrieve("Imgur", "AccessToken"); credential.RetrievePassword(); ApiClient.InitializeApiClient(credential.Password); rootFrame.Navigate(typeof(Pages.Upload), op); } else { op.ReportError("Please sign in to Imgur first and try again."); } }
public static async Task LoadData(List <Course> courses) { courses.Clear(); var vault = new Windows.Security.Credentials.PasswordVault(); if (vault.RetrieveAll().Count == 0) { return; } string userId = vault.FindAllByResource("LearnTHU")[0].UserName; StorageFolder storageFolder = ApplicationData.Current.LocalFolder; StorageFile file = (StorageFile)await storageFolder.TryGetItemAsync(userId + ".json"); if (file == null) { return; } string json = await FileIO.ReadTextAsync(file); JsonArray jsonArr = JsonArray.Parse(json); foreach (IJsonValue obj in jsonArr) { if (obj.ValueType == JsonValueType.Object) { courses.Add(jsonToCourse(obj.GetObject())); } } return; }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="args">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; var titleBarCore = CoreApplication.GetCurrentView().TitleBar; titleBarCore.ExtendViewIntoTitleBar = true; var titleBar = ApplicationView.GetForCurrentView().TitleBar; titleBar.ButtonBackgroundColor = Colors.Transparent; titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (args.PrelaunchActivated == false) { if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter var credentialVault = new Windows.Security.Credentials.PasswordVault(); var credentialList = credentialVault.RetrieveAll(); if (credentialList.Count > 0) { var credential = credentialVault.Retrieve("Imgur", "AccessToken"); credential.RetrievePassword(); ApiClient.InitializeApiClient(credential.Password); (Window.Current.Content as Frame).Navigate(typeof(Pages.MainPage)); } else { rootFrame.Navigate(typeof(Pages.Login), args.Arguments); } } // Ensure the current window is active Window.Current.Activate(); } }
static void Main(string[] args) { Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault(); Console.WriteLine("{0}", vault.GetType()); foreach (var cred in vault.RetrieveAll()) { cred.RetrievePassword(); DumpCredentials(cred); } }
private void btnBorrar_Click(object sender, RoutedEventArgs e) { var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.RetrieveAll(); foreach (var item in credentialList) { vault.Remove(item); } }
private void SetWifiProfile(string ssid, string password) { //Clear pre-existing WiFi Profiles. var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.RetrieveAll(); foreach (var cred in credentialList) { vault.Remove(cred); } //Save current WiFi Profile vault.Add(new Windows.Security.Credentials.PasswordCredential("wifiProfile", ssid, password)); }
private static Windows.Security.Credentials.PasswordCredential GetCredentialFromLocker() { Windows.Security.Credentials.PasswordCredential credential = null; var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.RetrieveAll(); if (credentialList.Count > 0) { credential = credentialList[0]; } return(credential); }
/// <summary> /// 在应用程序由最终用户正常启动时进行调用。 /// 将在启动应用程序以打开特定文件等情况下使用。 /// </summary> /// <param name="e">有关启动请求和过程的详细信息。</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Window.Current.Content as Frame; // 不要在窗口已包含内容时重复应用程序初始化, // 只需确保窗口处于活动状态 if (rootFrame == null) { // 创建要充当导航上下文的框架,并导航到第一页 rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: 从之前挂起的应用程序加载状态 } // 将框架放在当前窗口中 Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // 当导航堆栈尚未还原时,导航到第一页, // 并通过将所需信息作为导航参数传入来配置 // 参数 var vault = new Windows.Security.Credentials.PasswordVault(); if (vault.RetrieveAll().Count == 0) { rootFrame.Navigate(typeof(View.Login), e.Arguments); } else { rootFrame.Navigate(typeof(View.MainPage), e.Arguments); } } // 确保当前窗口处于活动状态 Window.Current.Activate(); }
private void btnLogin_Click(object sender, RoutedEventArgs e) { //Logear al usuario y string resourceName = "UWPAppPasswordVault"; string usuario = txtNombre.Text; string contrasena = txtPassword.Text; Windows.Security.Credentials.PasswordCredential credencial = null; //guardarlo en el PassportVault si no existe y es el primero //--> recuperar del vault la lista var vault = new Windows.Security.Credentials.PasswordVault(); //Controlar exccepcion cuando esta vacia //try** var credentialList = vault.RetrieveAll(); //var credentialList = vault.FindAllByResource(resourceName); //--> mirar si esta vacia if (credentialList.Count == 0) { //--> añadirle a la lista vault.Add(new Windows.Security.Credentials.PasswordCredential( resourceName, usuario, contrasena)); Frame.Navigate(typeof(Servicio)); } //Si no es el primero y existe enviarle a Servicio //Si no es el primero y no existe mandarle a vienvenida if (credentialList.Count > 0) { //**Si implementamos el try //credencial = credentialList.FirstOrDefault(); credencial = credentialList[0]; if (credencial.UserName == usuario && credencial.Resource == resourceName) { Frame.Navigate(typeof(Servicio)); } else { Frame.Navigate(typeof(BienVenida)); } } }
private void logoutButton_Click(object sender, RoutedEventArgs e) { try { Frame rootFrame = Window.Current.Content as Frame; if (rootFrame != null) { GnarlyClient.Instance.Disconnect(); Windows.Security.Credentials.PasswordVault valut = new Windows.Security.Credentials.PasswordVault(); foreach (var c in valut.RetrieveAll()) { valut.Remove(c); } rootFrame.Navigate(typeof(LoginSelection)); } } catch (Exception exception) { App.LogUnhandledError(exception); } }