private void Btn_Login_Click(object sender, RoutedEventArgs e) { string path = "registro.xml"; XDocument xmlDoc = XDocument.Load(path); XElement xmlListaPersone = xmlDoc.Element("persone"); var xmlPersona = xmlListaPersone.Elements("persona"); foreach (var item in xmlPersona) { XElement xmlEmail = item.Element("email"); XElement xmlUsername = item.Element("username"); XElement xmlPassword = item.Element("password"); if (xmlUsername.Value == Txt_Username.Text && xmlPassword.Value == Txt_Password.Text || xmlEmail.Value == Txt_Username.Text && xmlPassword.Value == Txt_Password.Text) { Museo.MainWindow mainWindow = new Museo.MainWindow(); this.Close(); mainWindow.Show(); break; } else { MessageBox.Show("Verifica la correttezza dei dati inseriti", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Error); Txt_Username.Focus(); break; } } }
private void AccountUpdate_Click(object sender, EventArgs e) { using (MySqlConnection mysqlCon = new MySqlConnection(@"Server=" + ip + ";Database=osa_queuing;Uid=root;Pwd=;")) { try { mysqlCon.Open(); String sql = "UPDATE accounts SET username = @username, password = @password, first_name = @firstname, last_name = @lastname WHERE account_id = @accountid"; if (!(Txt_Password.Text.Equals(Txt_ConfPass.Text))) { MessageBox.Show("Both of your new passwords do not match. Please try again.", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (Txt_Firstname.Equals("") || Txt_Lastname.Equals("") || Txt_Username.Equals("") || Txt_Password.Equals("")) { MessageBox.Show("Please fill in all the needed details.", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MySqlCommand cmd = new MySqlCommand(sql, mysqlCon); cmd.Parameters.AddWithValue("@username", Txt_Username.Text); cmd.Parameters.AddWithValue("@password", GetPasswordHashed(Txt_Password.Text)); cmd.Parameters.AddWithValue("@firstname", Txt_Firstname.Text); cmd.Parameters.AddWithValue("@lastname", Txt_Lastname.Text); cmd.Parameters.AddWithValue("@accountid", Emp.empId); cmd.ExecuteNonQuery(); MessageBox.Show("Your account has successfully updated!", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception) { MessageBox.Show("Sorry, we can't update your account details/credentials as your connection was interrupted.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void UpdatePassword() { String ip = Txt_ServerIP.Text; using (MySqlConnection mysqlCon = new MySqlConnection(@"Server=" + ip + ";Database=osa_queuing;Uid=root;Pwd=;")) { mysqlCon.Open(); String sql = "UPDATE accounts SET password = @password WHERE username = @username"; if (!(Txt_Password.Text.Equals(Txt_ConfPass.Text))) { MessageBox.Show("Both of your new passwords do not match. Please try again.", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (Txt_Username.Equals("") || Txt_Password.Equals("") || Txt_ServerIP.Equals("")) { MessageBox.Show("Please fill in all the needed details.", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MySqlCommand cmd = new MySqlCommand(sql, mysqlCon); cmd.Parameters.AddWithValue("@username", Txt_Username.Text); cmd.Parameters.AddWithValue("@password", GetPasswordHashed(Txt_Password.Text)); cmd.ExecuteNonQuery(); MessageBox.Show("Your account has successfully updated!", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } }
private void Btn_Login_Click(object sender, EventArgs e) { if (MaxAttempts == 0) { Close(); } else { while (attempt <= MaxAttempts) { if (Txt_Username.Text != username) { // username is incorrect MessageBox.Show("Invalid username, " + (MaxAttempts - attempt) + " attempts remaining"); attempt++; Txt_Username.Clear(); Txt_Password.Clear(); return; } else { // username is correct // so check password if (Txt_Password.Text != password) { // Incorrect password attempt++; MessageBox.Show("Incorrect password," + (MaxAttempts - attempt) + " attempts remaining"); Txt_Username.Clear(); Txt_Password.Clear(); return; } else { //Both are correct attempt = 0; // reset the number of attempts MessageBox.Show("Login successful"); Btn_Login.Text = "Logout"; Txt_Username.Clear(); Txt_Password.Clear(); // this.Width = 1600; break; // come out of while loop }//endif }//endif }//end while } }
public Registration_Page() { try { InitializeComponent(); Txt_Email.Completed += (s, a) => Txt_Username.Focus(); Txt_Username.Completed += (s, a) => Txt_password.Focus(); Txt_password.Completed += (s, a) => Txt_passwordConfirm.Focus(); //Txt_passwordConfirm.Completed += (s, a) => Btn_Register_OnClicked(s, a); } catch (Exception ex) { var exception = ex.ToString(); } }
// Button Connetti private void Btn_Connetti_Click(object sender, RoutedEventArgs e) { // Controlli generali if (Txt_Username.Text == "Nome utente") { MessageBox.Show("Attenzione, devi inserire un nome utente", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Warning); Txt_Username.Focus(); return; } if (Txt_IpAddress.Text == "Indirizzo IP") { MessageBox.Show("Attenzione, devi inserire un indirizzo IP", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Warning); Txt_IpAddress.Focus(); return; } if (Txt_porta.Text == "Numero porta") { MessageBox.Show("Attenzione, devi inserire un numero di porta", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Warning); Txt_porta.Focus(); return; } // Creazione istanza client = new AsyncSocketClient(); // Passaggio dei parametri ai metodi client.SetServerIPAddress(Txt_IpAddress.Text); client.SetServerPort(Txt_porta.Text); // Connessione al server client.ConnettiAlServer(); client.Invia(Txt_Username.Text); Chat chat = new Chat(); chat.Show(); this.Hide(); }
private void Btn_Login_Click(object sender, RoutedEventArgs e) { bool flag = true; string path = "registro.xml"; XDocument xmlDoc = XDocument.Load(path); XElement xmlListaPersone = xmlDoc.Element("persone"); var xmlPersona = xmlListaPersone.Elements("persona"); foreach (var item in xmlPersona) { XElement xmlEmail = item.Element("email"); XElement xmlUsername = item.Element("username"); XElement xmlPassword = item.Element("password"); if (xmlUsername.Value == Txt_Username.Text && xmlPassword.Value == Pwd_Password.Password || xmlEmail.Value == Txt_Username.Text && xmlPassword.Value == Pwd_Password.Password) { Museo.MainWindow mainWindow = new Museo.MainWindow(); MessageBox.Show($"Ciao {xmlUsername.Value}, goditi al meglio lo Smart Museum", "WELCOME", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); mainWindow.Show(); flag = false; break; } else if (xmlUsername.Value == Txt_Username.Text && xmlPassword.Value != Pwd_Password.Password || xmlEmail.Value == Txt_Username.Text && xmlPassword.Value != Pwd_Password.Password) { MessageBox.Show("Verifica la correttezza dei dati inseriti", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Error); Txt_Username.Focus(); flag = false; break; } } if (flag) { MessageBox.Show("Non sei registrato? Registrati ora!", "Avviso", MessageBoxButton.OK, MessageBoxImage.Question); } }