i have a LoginWindow with username and password to access in the software after that the user authenticated i want show in the next window(the mainWindow of the software) the name of the user authenticated in a TextBlock …i show a code snippet of my LoginWindow:
public partial class Window1 : Window { public Window1() { InitializeComponent(); } public bool ValidateApplicationUser(string userName, string password) { { var AuthContext = new DataClasses1DataContext(); var query = from c in AuthContext.Users where (c.Username == userName.ToLower() && c.Password == password.ToLower()) select c; if(query.Count() != 0 ) { return true; } return false; } } private void mahhh(object sender, RoutedEventArgs e) { bool authenticated = true; { if (usernameTextBox.Text !='' && passwordTextBox.Text != '') { authenticated = ValidateApplicationUser(usernameTextBox.Text , passwordTextBox.Text); } } if (!authenticated) { MessageBox.Show('Invalid login. Try again.'); } else { MessageBox.Show('Congradulations! You're a valid user!'); MainWindow c = new MainWindow(); c.ShowDialog(); } } }
If I authenticate with the username’Marc’ in the MainWindow i will show the username ‘Marc’ in a TextBlock and I don’t know I make it? How I can do it?
Simply, Pass the UserName to the constructor of the Main window like this
And in the constructor of the main window receive the value in variable and do whatever you want with it, like this