private void AddOrUpdateWindowsCredential(UserCredential existingCredential, string password) { var passwordVault = new Windows.Security.Credentials.PasswordVault(); try { var windowsCredentials = passwordVault.FindAllByResource("Baconography"); var matchingWindowsCredential = windowsCredentials.FirstOrDefault(credential => string.Compare(credential.UserName, existingCredential.Username, StringComparison.CurrentCultureIgnoreCase) == 0); if (matchingWindowsCredential != null) { matchingWindowsCredential.RetrievePassword(); if (matchingWindowsCredential.Password != password) { passwordVault.Remove(matchingWindowsCredential); } else { passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } } else { passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } } catch { passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } }
private async void LoginBtn_Click(object sender, RoutedEventArgs e) { progressRing.Visibility = Visibility.Visible; progressRing.IsActive = true; LoginBtn.IsEnabled = false; try { var web = new Web(); var result = await web.Login(UserID.Text, Passwd.Password); if (result == Web.LoginResult.Success) { var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential( "LearnTHU", UserID.Text, Passwd.Password)); new MainModel(web); ((Frame)Window.Current.Content).Navigate(typeof(MainPage)); return; } else if (result == Web.LoginResult.Failed) { progressRing.Visibility = Visibility.Collapsed; progressRing.IsActive = false; LoginBtn.IsEnabled = true; await new Windows.UI.Popups.MessageDialog(@"用户名或密码错误").ShowAsync(); return; } } catch { } progressRing.Visibility = Visibility.Collapsed; progressRing.IsActive = false; LoginBtn.IsEnabled = true; await new Windows.UI.Popups.MessageDialog(@"登录遇到了问题…").ShowAsync(); }
private static void _AddOrUpdateAccount(string mailAddress, string password) { var id = mailAddress; if (String.IsNullOrWhiteSpace(mailAddress) || String.IsNullOrWhiteSpace(password)) { throw new Exception(); } var vault = new Windows.Security.Credentials.PasswordVault(); try { var credential = vault.Retrieve(nameof(HohoemaApp), id); vault.Remove(credential); } catch { } { var credential = new Windows.Security.Credentials.PasswordCredential(nameof(HohoemaApp), id, password); vault.Add(credential); } }
private static void _AddOrUpdateAccount(string mailAddress, string password) { var id = mailAddress; if (String.IsNullOrWhiteSpace(mailAddress) || String.IsNullOrWhiteSpace(password)) { throw new Models.Infrastructure.HohoemaExpception(); } var vault = new Windows.Security.Credentials.PasswordVault(); try { var credential = vault.Retrieve(AccountResrouceKey, id); vault.Remove(credential); } catch { } { var credential = new Windows.Security.Credentials.PasswordCredential(AccountResrouceKey, id, password); vault.Add(credential); } }
private async Task <bool> changeAccountHelper() //false for anonymous { var dialog = new PasswordDialog(); Password password; this.progressLogin.IsActive = true; try { password = await dialog.getCredentialAsyc(); this.progressLogin.IsActive = false; } catch (UserCancelException) { //user choose to stay anonymous DataAccess.setLocalSettings("username", "__anonymous"); return(false); } //save credential //TODO: wrap as a function and move into DataAccess DataAccess.setLocalSettings("toasted_assignments", ""); DataAccess.setLocalSettings("username", password.username); var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential( "Tsinghua_Learn_Website", password.username, password.password)); return(true); }
private async void TryLoginOrRegister() { StatusBar bar = StatusBar.GetForCurrentView(); await bar.ProgressIndicator.ShowAsync(); await bar.ShowAsync(); Frame rootFrame = Window.Current.Content as Frame; bar.ProgressIndicator.Text = "Trying to log in..."; if (email.Text == null || password.Password == null) { await new MessageDialog("Your password was incorrect. Please try again", "Incorrect password").ShowAsync(); return; } if (!(await api.LoginWithEmail(email.Text, password.Password))) { await new MessageDialog("Your password was incorrect. Please try again", "Incorrect password").ShowAsync(); } else { Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential("email", email.Text, password.Password)); if (!rootFrame.Navigate(typeof(MainPage), api)) { throw new Exception("Failed to create initial page"); } } await bar.HideAsync(); }
public void Protect(string key, string value) { var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential( Windows.ApplicationModel.Package.Current.Id.Name, key, value)); }
public void onLoginClick(object sender, RoutedEventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Config.URI + "api/auth/playerlogin"); D.p(request.ToString()); request.Method = "POST"; request.ContentType = "application/json; charset=utf-8"; test = GetUserInfoJson(); request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request); while (true) { if (isLogin.Length != 0 && String.Equals("success", isLogin)) { var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential(resourceName, txtEmail.Text, txtPassword.Password)); var loginCredential = GetCredentialFromLocker(); Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(HomePage)); return; } else if (isLogin.Length != 0 && String.Equals("failed", isLogin)) { D.p("went in failure"); //errorLoginMsg.Text = "Wrong email or password"; return; } } }
private void SignUpBtn_Click(object sender, RoutedEventArgs e) { if ((string.IsNullOrEmpty(UsernameTxt.Text) == true) || (string.IsNullOrEmpty(PasswordTxt.Password) == true) || (string.IsNullOrEmpty(ConfirmPasswordTxt.Password) == true) || (AvatarComboBox.SelectedIndex == -1)) { ErrorTxt.Text = "Enter all the fields!"; } else { string userName = UsernameTxt.Text; bool isValid = UserDB.CheckValidUser(UsernameTxt.Text); if (isValid == true) { ErrorTxt.Text = "User Name already exists!"; } else { if (PasswordTxt.Password.Equals(ConfirmPasswordTxt.Password)) { string avatar = ((string)AvatarComboBox.SelectedValue); AvatarComboBox.SelectedIndex = -1; UserDB.AddUser(UsernameTxt.Text, avatar); var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential("TaskManagerApp", UsernameTxt.Text, PasswordTxt.Password)); Frame.Navigate(typeof(LoginPage)); } else { ErrorTxt.Text = "Passwords don't match!"; } } } }
private async Task SaveCredentialsAsync() { if (!string.IsNullOrWhiteSpace(Settings.Username) && !string.IsNullOrWhiteSpace(Settings.Password)) { await Task.Run(() => { var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential("BuildLight", Settings.Username, Settings.Password)); }); } }
public void Store(string key, string value) { var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential() { Password = value, UserName = key, Resource = key, }); }
public void SetSecured(string id, string value, string clientId, string service, string sharedGroup) { var vault = new Windows.Security.Credentials.PasswordVault(); try { var pass = vault.Retrieve(ResourceIdentifier, $"{clientId}-{id}-{service}"); if (pass != null) vault.Remove(pass); } catch { } vault.Add(new Windows.Security.Credentials.PasswordCredential(ResourceIdentifier, $"{clientId}-{id}-{service}", value)); }
private async void LoginBtn_Click(object sender, RoutedEventArgs e) { UserToken userToken; try { userToken = await OAuthClient.Authenticate(); } catch (OAuthFailedException) { return; } var credentialVault = new Windows.Security.Credentials.PasswordVault(); credentialVault.Add(new Windows.Security.Credentials.PasswordCredential("Imgur", "Username", userToken.Username)); credentialVault.Add(new Windows.Security.Credentials.PasswordCredential("Imgur", "UserId", userToken.UserId)); credentialVault.Add(new Windows.Security.Credentials.PasswordCredential("Imgur", "AccessToken", userToken.AccessToken)); credentialVault.Add(new Windows.Security.Credentials.PasswordCredential("Imgur", "RefreshToken", userToken.RefreshToken)); ApiClient.InitializeApiClient(userToken.AccessToken); (Window.Current.Content as Frame).Navigate(typeof(MainPage)); }
//fonction executée quand on appuie sur le bouton private async void login_button(object sender, RoutedEventArgs ev) { string login = nom.Text.ToLower(); if (pass.Password == "" || login == "") { ecrire("Veuillez entrer vos identifiants."); return; } loginProgress.IsActive = true; ecrire(""); //loginProgress.Visibility = Visibility.Visible; await Task.Delay(500); //Bypass pour le test de certification Windows Store: //Active le mode TEST pour cette session, qui fournira pour chaque call API des données préparées à l'avance. if (login == "windows10test" && pass.Password == "Developers") { ArelAPI.DataStorage.enableTestMode(); Frame.Navigate(typeof(acceuil)); return; } Boolean connectionState = await API.LoginARELUserAsync(login, pass.Password); if (connectionState) { if (stayConnect) { //On déclare un flag pour indiquer qu'on sauvegarde les données de login localSettings.Values["stayConnect"] = true; //On stocke login/pass dans un Credential Locker var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential( "ARELUWP_User", login, pass.Password)); } Frame.Navigate(typeof(acceuil)); } else { //L'objet API logge l'erreur de connexion si il en arrive une. ecrire("Erreur de connexion: " + ArelAPI.DataStorage.getData("erreurLogin")); loginProgress.IsActive = false; await Task.Delay(500); } }
public void OnTimer(object sender, System.Timers.ElapsedEventArgs args) { System.Console.WriteLine("Application service is recalled after 10s"); SQLiteConnection conn = new SQLiteConnection(DB_Link.conn_link); // to store in SQLite daabase string strurltest = String.Format("url"); // fetch API WebRequest requestObjGet = WebRequest.Create(strurltest); requestObjGet.Method = "GET"; HttpWebResponse responseObjGet = null; responseObjGet = (HttpWebResponse)requestObjGet.GetResponse(); string strresult = null; // set null using (Stream stream = responseObjGet.GetResponseStream()) // in json format { StreamReader sr = new StreamReader(stream); strresult = sr.ReadToEnd(); sr.Close(); } var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); List <Comments> objList = (List <Comments>)serializer.Deserializer(strresult, typeof((List <Comments>))); foreach (Comments obj in objList) { string username = obj.username; string password = obj.password; SQLiteCommand cmd = new SQLiteCommand("insert into userInfo (user_name,user_pass) values ('" + text_user.Text + "','" + text_pass.Text + "')"); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); var vault = new Windows.Security.Credentials.PasswordVault(); var credential = new Windows.Security.Credentials.PasswordCredential( resource: "Sample Application", userName: this.text_username.Text, password: this.text_password.Text); vault.Add(credential); System.Console.WriteLine("Insertion Done in SQLite......"); } }
public void SetSecured(string id, string value, string clientId, string service, string sharedGroup) { var vault = new Windows.Security.Credentials.PasswordVault(); try { var pass = vault.Retrieve(ResourceIdentifier, $"{clientId}-{id}-{service}"); if (pass != null) { vault.Remove(pass); } } catch { } vault.Add(new Windows.Security.Credentials.PasswordCredential(ResourceIdentifier, $"{clientId}-{id}-{service}", value)); }
public static async Task <bool> SignIn(string discordToken, string refreshToken) { try { DiscordToken = discordToken; DiscordRefreshToken = refreshToken; DiscordUser = await DiscordApi.GetCurrentUser(); var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential( resourceName, DiscordUser.DiscordId, DiscordToken)); try { _ = await GetCurrentUser(); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <UWPCommLib.Api.UWPComm.Models.Error>(); if (ex.StatusCode == System.Net.HttpStatusCode.NotFound) { // The user does not exist yet, so create an account for them await UwpCommApi.PostUser(new Dictionary <string, string>() { { "name", DiscordUser.Username }, }); } } IsLoggedIn = true; OnLoginStateChanged(IsLoggedIn); } catch { IsLoggedIn = false; } return(IsLoggedIn); }
private async void Connection() { if (!ConnectionFieldsVerif()) { return; } IsBusy = true; AccountDataService accounDataService = new AccountDataService(); AppStaticInfo.Account = UserAccount; if (await accounDataService.Connect()) { // TODO garder la connexion après fermeture est activé par default il faudra le changer // TODO mettre le fait de resté connecté dans accountDataService et pareil pour vérifier si l'user était déjà connecté var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential( resourceName, UserAccount.Mail, UserAccount.Password)); ConnectionSuccessful(); } else { } }
private async void SavePodioCredentials(object sender, RoutedEventArgs e) { try { var vault = new Windows.Security.Credentials.PasswordVault(); try { var existingCredentials = vault.FindAllByResource("nyltformcapture"); foreach (var credential in existingCredentials) { vault.Remove(credential); } } catch { } vault.Add(new Windows.Security.Credentials.PasswordCredential( "nyltformcapture", AppID.Text, AppSecret.Password)); CredentialsSaved(); } catch (Exception ex) { await Notify(ex.Message); } }
private void AddOrUpdateRecentLoginAccount(string mail, string password) { try { var vault = new Windows.Security.Credentials.PasswordVault(); try { var oldItems = vault.FindAllByResource(nameof(Uncord)); foreach (var vaultItem in oldItems) { vault.Remove(vaultItem); } oldItems = null; } catch { } vault.Add(new Windows.Security.Credentials.PasswordCredential( nameof(Uncord), mail, password)); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
public async Task LoginVk(string login, string password) { //var accessToken = await this._vkontakte.Login(login, password, VkScopeSettings.CanAccessFriends | VkScopeSettings.CanAccessAudios | VkScopeSettings.CanAccessVideos | VkScopeSettings.CanAccessStatus | VkScopeSettings.CanAccessWall | VkScopeSettings.CanAccessGroups , null, null); var accessToken = await this._vkontakte.Login(login, password, VkScopeSettings.CanAccessAudios, null, null); if (accessToken == null || accessToken.Token == null) { throw new Exception(AppResources.Strings["ErrorLoginCommon"], new ArgumentException("AccessToken is empty")); } ApplicationService.Instance.Settings.AccessToken = accessToken.Token; ApplicationService.Instance.Settings.UserId = accessToken.UserId; // ApplicationService.Instance.Settings.Save(); var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential( "VkApp", ApplicationService.Instance.Settings.UserId, ApplicationService.Instance.Settings.AccessToken)); //var vault = new PasswordVault(); Messenger.Default.Send <LoginMessage>(new LoginMessage { Type = LoginType.LogIn, IsSuccess = true }); Messenger.Default.Send <GoHomeMessage>(new GoHomeMessage()); }
private void AddOrUpdateWindowsCredential(UserCredential existingCredential, string password) { var passwordVault = new Windows.Security.Credentials.PasswordVault(); try { var windowsCredentials = passwordVault.FindAllByResource("Baconography"); var matchingWindowsCredential = windowsCredentials.FirstOrDefault(credential => string.Compare(credential.UserName, existingCredential.Username, StringComparison.CurrentCultureIgnoreCase) == 0); if (matchingWindowsCredential != null) { matchingWindowsCredential.RetrievePassword(); if (matchingWindowsCredential.Password != password) { passwordVault.Remove(matchingWindowsCredential); } else passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } else passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } catch { passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } }
private async void mlogin() { var vault = new Windows.Security.Credentials.PasswordVault(); StuNumTextBox.IsEnabled = false; IdNumPasswordBox.IsEnabled = false; LoginProgressBar.IsActive = true; this.Focus(FocusState.Pointer); LoginButton.Visibility = Visibility.Collapsed; noLoginButton.Visibility = Visibility.Collapsed; List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>(); paramList.Add(new KeyValuePair<string, string>("stuNum", StuNumTextBox.Text)); paramList.Add(new KeyValuePair<string, string>("idNum", System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(IdNumPasswordBox.Password)))); //paramList.Add(new KeyValuePair<string, string>("idNum", IdNumPasswordBox.Password)); string login = await NetWork.getHttpWebRequest("cyxbsMobile/index.php/Home/Verify/verifyLogin", paramList); Debug.WriteLine("login->" + login); if (login != "") { try { JObject obj = JObject.Parse(login); if (Int32.Parse(obj["status"].ToString()) == 200) { vault.Add(new Windows.Security.Credentials.PasswordCredential(resourceName, StuNumTextBox.Text, IdNumPasswordBox.Password)); //appSetting.Values["stuNum"] = StuNumTextBox.Text; //appSetting.Values["idNum"] = IdNumPasswordBox.Password; JObject dataobj = JObject.Parse(obj["data"].ToString()); appSetting.Values["name"] = dataobj["name"].ToString(); appSetting.Values["classNum"] = dataobj["classNum"].ToString(); appSetting.Values["gender"] = dataobj["gender"].ToString(); appSetting.Values["major"] = dataobj["major"].ToString(); appSetting.Values["college"] = dataobj["college"].ToString(); appSetting.Values["CommunityPerInfo"] = false; if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList")) { if (JumpList.IsSupported()) SetSystemGroupAsync(); else if (JumpList.IsSupported()) DisableSystemJumpListAsync(); } appSetting.Values["isUseingBackgroundTask"] = true; Frame.Navigate(typeof(MainPage), "/kb"); } else if (Int32.Parse(obj["status"].ToString()) == -100) { Utils.Message("学号不存在"); noLoginButton.Visibility = Visibility.Visible; } else if (Int32.Parse(obj["status"].ToString()) == 201) { Utils.Message("学号或密码错误"); noLoginButton.Visibility = Visibility.Visible; } else { Utils.Message(obj["info"].ToString()); noLoginButton.Visibility = Visibility.Visible; } } catch (Exception) { Debug.WriteLine("登陆->返回值解析异常"); } } else Utils.Message("网络异常"); LoginButton.Visibility = Visibility.Visible; LoginProgressBar.IsActive = false; StuNumTextBox.IsEnabled = true; IdNumPasswordBox.IsEnabled = true; // Debug.WriteLine(StuNumTextBox.FocusState); //StuNumTextBox.Focus(FocusState.Unfocused); // IdNumPasswordBox.Focus(FocusState.Pointer); }
private async void RegisterButton_Tapped(object sender, TappedRoutedEventArgs e) { if (Register.Visibility == Windows.UI.Xaml.Visibility.Collapsed) { Register.Visibility = Windows.UI.Xaml.Visibility.Visible; } else { Frame rootFrame = Window.Current.Content as Frame; StatusBar bar = StatusBar.GetForCurrentView(); await bar.ProgressIndicator.ShowAsync(); await bar.ShowAsync(); bar.ProgressIndicator.Text = "Trying to register..."; bool allok = true; if (firstname.Text == null) { firstname.BorderBrush = new SolidColorBrush() { Color = Windows.UI.Colors.Red }; allok = false; } if (lastname.Text == null) { lastname.BorderBrush = new SolidColorBrush() { Color = Windows.UI.Colors.Red }; allok = false; } if (email.Text == null || !Regex.IsMatch(email.Text, "[^@]+@[^@]+.[a-zA-Z]{2,6}")) { email.BorderBrush = new SolidColorBrush() { Color = Windows.UI.Colors.Red }; allok = false; } if (password.Password == null || password.Password.Length < 6) { password.BorderBrush = new SolidColorBrush() { Color = Windows.UI.Colors.Red }; allok = false; } if (timezone.SelectedItem == null) { timezone.BorderBrush = new SolidColorBrush() { Color = Windows.UI.Colors.Red }; allok = false; } if (allok) { if (await api.RegisterWithEmail(firstname.Text, lastname.Text, email.Text, password.Password, (timezone.SelectedItem as string))) { Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(new Windows.Security.Credentials.PasswordCredential("email", email.Text, password.Password)); if (!rootFrame.Navigate(typeof(MainPage), api)) { throw new Exception("Failed to create initial page"); } } } } }