-1

I am trying to create a login system for a uwp(winui3) app. In the login window the user enters his credentials and on clicking the login button he/she is redirected to mainwindow. But I get an Unhandled exception error.

App.xaml.cs

 protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
    {
        loginpage=new LoginWindow();
        loginpage.Activate();}
     

LoginWindow.xaml.cs

        private void Login_Click(object sender, RoutedEventArgs e)
    {
        string query = "select * from ***** where username='" + username.Text + "' and password='" + password.Text + "'";
        DataTable dt = new DataTable();
        dt = Tools.getdatafromDATABASE(query);
        if (dt.Rows.Count == 0)
        {
        //Display incorrect username and password message
        }
        else
        {
           //Redirect to MainWindow
           Window mainwindow = new MainWindow();
            mainwindow.Activate();
        }
    }
    }

MainWindow.cs

        public MainWindow()
    {
        this.InitializeComponent();
        MainContent.Navigate(typeof(HomePage));
    }

Exception

Rohith
  • 1
  • 1
  • 4
  • please use ***parameterised queries*** - building SQL queries by concatenation etc. is a recipe for disaster. not only is it a source for many hard to debug syntax errors, it's also a wide, open gate for ***[SQL Injection attacks](https://bobby-tables.com/)***. also: ***never ever ever ever*** store passwords as plain text! – Franz Gleichmann Jan 27 '22 at 09:40
  • I will try it but I have many other functions within the mainwindow.cs where the query is defined in the way above and they work perfectly! – Rohith Jan 27 '22 at 09:46
  • it doesn't matter. it is a horrible security flaw, and an absolute _no-go_ - the only place where concatenated SQL-queries should exist is in articles that tell you to use parameterised statements - _it can not be stressed enough_ – Franz Gleichmann Jan 27 '22 at 09:53

1 Answers1

2

Multiple top-level windows are not supported in Win UI 3 / Windows App SDK 1.0. Maybe in 1.1, at least Microsoft promised so.

You can use a ContentDialog for your login window.

Nick
  • 4,787
  • 2
  • 18
  • 24