コード例 #1
0
        private async void Signin(object sender, RoutedEventArgs e)
        {
            if (username.Text == "" || password.Password == "")
            {
                MessageDialog messagebox = new MessageDialog("Do not leave blank on any field.");
                await messagebox.ShowAsync();
            }
            else
            {
                var logincredentials = new LoginCredentials();
                try
                {
                    SqlConnection  connection  = new SqlConnection(@"Data Source=DESKTOP-2UB7OKA;Initial Catalog=RegisterLogin;Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True");
                    SqlDataAdapter dataadapter = new SqlDataAdapter("SELECT COUNT(*) FROM Register WHERE Username='******' AND Password='******'", connection);
                    DataTable      datatable   = new DataTable();
                    dataadapter.Fill(datatable);
                    if (datatable.Rows[0][0].ToString() == "1")
                    {
                        logincredentials.UserName           = username.Text;
                        logincredentials.NotificationToggle = "True";
                        MessageDialog messagebox = new MessageDialog("Login successfully.");
                        await messagebox.ShowAsync();

                        connection.Close();
                        this.Frame.Navigate(typeof(UserDashboard), logincredentials);
                    }
                    else
                    {
                        MessageDialog messagebox = new MessageDialog("Invalid User! Please check your username and password.");
                        await messagebox.ShowAsync();

                        this.Frame.Navigate(typeof(Login));
                    }
                }
                catch (Exception ex)
                {
                    MessageDialog messagebox = new MessageDialog("Database Connection Error." + ex);
                    await messagebox.ShowAsync();

                    this.Frame.Navigate(typeof(Login));
                }
            }
        }
コード例 #2
0
        private async void Save(object sender, RoutedEventArgs e)
        {
            if (Email.Text == "" || Password.Password == "" || ConPassword.Password == "")
            {
                MessageDialog messagebox = new MessageDialog("Do not leave blank on any field.");
                await messagebox.ShowAsync();
            }
            else if (ValidatePassword(Password.Password) == false)
            {
                MessageDialog messagebox = new MessageDialog("The password have to be between 8-15 characters and a combination of UpperCase and LowerCase letter as well as digit number. Your current password is " + Password.Password);
                await messagebox.ShowAsync();

                Password.Password = "";
            }
            else if (ValidateEmail(Email.Text) == false)
            {
                MessageDialog messagebox = new MessageDialog("The email address is not in the correct format. Your current email address is " + Email.Text);
                await messagebox.ShowAsync();

                Email.Text = "";
            }
            else if (Password.Password != ConPassword.Password)
            {
                MessageDialog messagebox = new MessageDialog("The password is not a match. Your current password is " + Password.Password);
                await messagebox.ShowAsync();

                Password.Password = "";
            }
            else
            {
                string        connetionString = null;
                SqlConnection connection;
                SqlCommand    command;

                connetionString =
                    "Data Source=DESKTOP-2UB7OKA;Initial Catalog=RegisterLogin;Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True";

                connection = new SqlConnection(connetionString);
                try
                {
                    connection.Open();
                    command = new SqlCommand(
                        "UPDATE Register SET EmailAddress=@NEmailAddress, Password=@NPassword WHERE (Username = '******')", connection);
                    {
                        command.Parameters.AddWithValue("@NEmailAddress", Email.Text);
                        command.Parameters.AddWithValue("@NPassword", Password.Password);
                        command.ExecuteNonQuery();
                    }
                    connection.Close();
                    MessageDialog messagebox = new MessageDialog("The profile has been updated successfully.");
                    await messagebox.ShowAsync();

                    var logincredentials = new LoginCredentials();
                    logincredentials.UserName = Username.Text;
                    this.Frame.Navigate(typeof(UserDashboard), logincredentials);
                }
                catch (Exception ex)
                {
                    MessageDialog messagebox = new MessageDialog("Database Connection Error: " + ex);
                    await messagebox.ShowAsync();
                }
            }
        }