public static TravellerObject VerifyTraveller(string username, string hashedPassword) { ErrorMessage = "Wrong username or password."; TravellerObject returnObj = null; NpgsqlConnection conn = null; NpgsqlDataReader dr = null; try { conn = OpenConnectionAndGetReader("SELECT * from traveller WHERE email = :p0 AND password = :p1;", out dr, username, hashedPassword); if (dr.Read()) { string email = dr.GetFieldValue <string>(dr.GetOrdinal("email")); string _hashedPassword = dr.GetFieldValue <string>(dr.GetOrdinal("password")); string name = dr.GetFieldValue <string>(dr.GetOrdinal("name")); string address = dr.GetFieldValue <string>(dr.GetOrdinal("address")); string phone = dr.GetFieldValue <string>(dr.GetOrdinal("phone")); returnObj = new TravellerObject(email, _hashedPassword, name, address, phone); ErrorMessage = ""; } } finally { conn.Close(); } return(returnObj); }
private void b_save_Click(object sender, RoutedEventArgs e) { if (tb_email.Text == "" || pb_password.Password == "" || tb_name.Text == "" || tb_address.Text == "" || tb_phone.Text == "") { MessageBox.Show("Empty fields are not allowed.", "Error!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } TravellerObject newObject = new TravellerObject(tb_email.Text, SimpleHash.GenerateHashedPassword(tb_email.Text, pb_password.Password), tb_name.Text, tb_address.Text, tb_phone.Text); int rowsChanged = -1; if (newtraveller) { rowsChanged = DBConnection.InsertTraveller(newObject); } else { rowsChanged = DBConnection.UpdateTraveller(newObject, oldObject); } if (rowsChanged > 0) { parentWindow.parentWindow.UpdateAllChain(); Close(); } }
private void b_save_Click(object sender, RoutedEventArgs e) { if (tb_email.Text == "" || pb_password.Password == "" || pb_confirm_password.Password == "" || tb_name.Text == "" || tb_address.Text == "" || tb_phone.Text == "") { MessageBox.Show("Empty fields are not allowed.", "Error!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!(pb_password.Password == pb_confirm_password.Password)) { MessageBox.Show("The passwords in the passwords fields are not the same.", "Error!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } TravellerObject newObject = new TravellerObject(tb_email.Text, SimpleHash.GenerateHashedPassword(tb_email.Text, pb_password.Password), tb_name.Text, tb_address.Text, tb_phone.Text); if (DBConnection.InsertTraveller(newObject) > 0) { Authenticator.currentUser = newObject; parentWindow.TryLogin(tb_email.Text, pb_password.Password); Close(); } }
public ChangeTravellerWindow(HandleTravellerWindow _parent, TravellerObject _oldObject) { InitializeComponent(); Title = "Edit Traveller - " + Authenticator.GetUserInfo(); oldObject = _oldObject; tb_email.Text = oldObject.email; pb_password.Password = ""; tb_name.Text = oldObject.name; tb_address.Text = oldObject.address; tb_phone.Text = oldObject.phone; parentWindow = _parent; newtraveller = false; }
public ChangeMyInformationWindow(TravellerWindow _parent, TravellerObject _oldObject) { InitializeComponent(); Title = "Change My Information - " + Authenticator.GetUserInfo(); oldObject = _oldObject; tb_email.Text = oldObject.email; pb_password.Password = ""; pb_confirm_password.Password = ""; tb_name.Text = oldObject.name; tb_address.Text = oldObject.address; tb_phone.Text = oldObject.phone; parentWindow = _parent; }
private void b_choose_Click(object sender, RoutedEventArgs e) { if (lv_lista.SelectedItem != null) { TravellerObject selected = (TravellerObject)lv_lista.SelectedItem; parentWindow.tb_traveller.Text = selected.email; Close(); } else { MessageBox.Show("Nothing selected.", "Error!", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static int DeleteTraveller(TravellerObject oldObject) { int bookingsCount = 0; bookingsCount = ExecuteAndGetScalar("SELECT count(*) FROM booking WHERE booking.traveller = :p0;", oldObject.email); int affectedRows = -1; MessageBoxResult result = MessageBox.Show("If you remove this traveller a total of " + bookingsCount + " bookings will also be removed! Do you still wish to remove this traveller?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { ExecuteAndGetNonQuery("DELETE FROM booking WHERE booking.traveller = :p0;", oldObject.email); affectedRows = ExecuteAndGetNonQuery("DELETE FROM traveller WHERE email = :p0;", oldObject.email); } return(affectedRows); }
public static int UpdateTraveller(TravellerObject newObject, TravellerObject oldObject) { return(ExecuteAndGetNonQuery("UPDATE traveller SET email = :p0, password = :p1, name = :p2, address = :p3, phone = :p4 WHERE email = :p5;", newObject.email, newObject.hashedPassword, newObject.name, newObject.address, newObject.phone, oldObject.email)); }
public static int InsertTraveller(TravellerObject newObject) { return(ExecuteAndGetNonQuery("INSERT INTO traveller (email, password, name, address, phone) values (:p0, :p1, :p2, :p3, :p4);", newObject.email, newObject.hashedPassword, newObject.name, newObject.address, newObject.phone)); }