private async void ClickSetting() { if (VerificationAuth.IsValidPassword(newPasswordBox.Password, newPasswordConfirmBox.Password)) //Check if both password match. { progressSetting.IsActive = true; backgroundWaiting.Visibility = Visibility.Visible; string ActualPassword = encryptionProvider.Decrypt(connectedUser.password); if (passwordActualBox.Password == ActualPassword) { connectedUser.password = encryptionProvider.Encrypt(newPasswordBox.Password);//Encrypt the password. await apiConnect.PostAsJsonAsync(connectedUser, "http://localhost/api/auth/changepassword.php"); progressSetting.IsActive = false; backgroundWaiting.Visibility = Visibility.Collapsed; ChangePasswordContentDialog dialog = new ChangePasswordContentDialog(parameter.rootFrame, parameter.connectedUser); await dialog.ShowAsync(); } else { progressSetting.IsActive = false; backgroundWaiting.Visibility = Visibility.Collapsed; VerificationAuth.AnimationErrorTextBox(passwordActualBox, errorSecondPasswordBoxStoryboard, errorSecondPasswordBoxColor, btnChange); //Launch error animation on textMail TextBox. errorActualPassword.Text = "Your actual password do not match."; } } else { progressSetting.IsActive = false; backgroundWaiting.Visibility = Visibility.Collapsed; VerificationAuth.AnimationErrorTextBox(newPasswordBox, errorFirstPasswordBoxStoryboard, errorFirstPasswordBoxColor, btnChange); //Launch error animation on passwordBox PasswordBox. VerificationAuth.AnimationErrorTextBox(newPasswordConfirmBox, errorSecondPasswordBoxStoryboard, errorSecondPasswordBoxColor, btnChange); //Launch error animation on passwordConfirmBox PasswordBox. errorNewPassword.Text = "The new passwords do not match."; } }
private async void ClickSignIn() { progressConnect.IsActive = true; backgroundWaiting.Visibility = Visibility.Visible; string userLogin = textUserOrMail.Text; string response = await apiConnect.PostAsJsonAsync(userLogin, "http://localhost/api/auth/login.php"); //HttpRequest to the URL with the user's information and recover the return. if (response != "NO") //If the username or the mail is in the database. { Users user = JsonConvert.DeserializeObject <Users>(response); //Deserialize the response of the php files to a dictionary. string passwordEncrypted = encryptionProvider.Decrypt(user.password); //Decrypt the password from the database. if (passwordEncrypted == passwordBox.Password) //Check if the decrypted password and the password from the PasswordBox match. { rootFrame.Navigate(typeof(MainPage), new FrameParameters(rootFrame, null, user), new DrillInNavigationTransitionInfo()); //Close this page and open MainPage. } else { progressConnect.IsActive = false; backgroundWaiting.Visibility = Visibility.Collapsed; VerificationAuth.AnimationErrorTextBox(textUserOrMail, errorFirstTextBoxStoryboard, errorFirstTextBoxColor, btnConnect); //Launch error animation on textUsername TextBox. VerificationAuth.AnimationErrorTextBox(passwordBox, errorSecondTextBoxStoryboard, errorSecondTextBoxColor, btnConnect); //Launch error animation on textUsername PasswordBox. errorPassword.Text = "Your identifiants are invalid."; } } else { progressConnect.IsActive = false; backgroundWaiting.Visibility = Visibility.Collapsed; VerificationAuth.AnimationErrorTextBox(textUserOrMail, errorFirstTextBoxStoryboard, errorFirstTextBoxColor, btnConnect); //Launch error animation on textUsername TextBox. errorUserOrMail.Text = "Your username or your email is invalid."; } }
private async void ClickRegister() { if (VerificationAuth.IsValidPassword(passwordBox.Password, passwordConfirmBox.Password)) //Check if both password match. { if (VerificationAuth.IsValidEmail(textMail.Text)) //Check if mail is valid. { progressRegister.IsActive = true; backgroundWaiting.Visibility = Visibility.Visible; string passwordEncrypted = encryptionProvider.Encrypt(passwordBox.Password); //Encrypt the password. Users registration = new Users(textUsername.Text, passwordEncrypted, textMail.Text, "1", "0"); //Create new Users with information. string response = await apiConnect.PostAsJsonAsync(registration, "http://localhost/api/auth/registration.php"); //HttpRequest to the URL with the user's information and recover the return. if (response == "YES") //Registration good. { rootFrame.Navigate(typeof(MainPage), new FrameParameters(rootFrame, null, registration), new DrillInNavigationTransitionInfo()); //Close this page and open MainPage. } else { progressRegister.IsActive = false; backgroundWaiting.Visibility = Visibility.Collapsed; Dictionary <string, string> dicoJSON = JsonConvert.DeserializeObject <Dictionary <string, string> >(response); //Deserialize the response of the php files to a dictionary. if (dicoJSON.ContainsKey("username")) //If the dictionary contains the key username. { VerificationAuth.AnimationErrorTextBox(textUsername, errorFirstTextBoxStoryboard, errorFirstTextBoxColor, btnRegister); //Launch error animation on textUsername TextBox. errorUsername.Text = "Your username is already taken."; } if (dicoJSON.ContainsKey("mail")) //If the dictionary contains the key mail. { VerificationAuth.AnimationErrorTextBox(textMail, errorSecondTextBoxStoryboard, errorSecondTextBoxColor, btnRegister); //Launch error animation on textMail TextBox. errorMail.Text = "Your email is already taken."; } } } else { VerificationAuth.AnimationErrorTextBox(textMail, errorFirstTextBoxStoryboard, errorFirstTextBoxColor, btnRegister); //Launch error animation on textMail TextBox. errorMail.Text = "Your email is invalid."; } } else { VerificationAuth.AnimationErrorTextBox(passwordBox, errorFirstTextBoxStoryboard, errorFirstTextBoxColor, btnRegister); //Launch error animation on passwordBox PasswordBox. VerificationAuth.AnimationErrorTextBox(passwordConfirmBox, errorSecondTextBoxStoryboard, errorSecondTextBoxColor, btnRegister); //Launch error animation on passwordConfirmBox PasswordBox. errorPassword.Text = "The passwords do not match."; } }