Example #1
0
        private void LogInButton(object sender, RoutedEventArgs e)
        {
            string        connectionString = ("Data Source=MSI-JORDI\\SQLEXPRESS;Initial Catalog = BankAppDB; Integrated Security = True");
            SqlConnection conn             = new SqlConnection(connectionString);

            conn.Open();

            UserName = User.Text;

            SqlCommand checkUser = new SqlCommand("Select Count (UserName) From UserInfo Where UserName='******';", conn);
            string     command   = checkUser.ExecuteScalar().ToString();

            if (command == "0")
            {
                MessageBox.Show("This username doesn't exists, make sure you have wrote it correctly.");
            }

            else
            {
                SqlCommand checkPassword = new SqlCommand("Select Password From UserInfo Where UserName='******';", conn);
                string     command2      = checkPassword.ExecuteScalar().ToString();

                if (Psswd.Password == command2)
                {
                    Operations_2 operations = new Operations_2();
                    this.Close();
                    operations.ShowDialog();
                }

                else
                {
                    MessageBox.Show("Incorrect password, make sure you have wrote it correctly.");
                }
            }
        }
Example #2
0
        private void RegisterBttn(object sender, RoutedEventArgs e)
        {
            UserName = User.Text;

            string        connectionString = ("Data Source=MSI-JORDI\\SQLEXPRESS;Initial Catalog = BankAppDB; Integrated Security = True");
            SqlConnection conn             = new SqlConnection(connectionString);

            conn.Open();
            SqlCommand checkUser = new SqlCommand("Select Count (UserName) From UserInfo Where UserName='******';", conn);
            string     command   = checkUser.ExecuteScalar().ToString();

            if (command == "1")
            {
                MessageBox.Show("This username already exists, please try with another one.");
            }

            else
            {
                if (ConfirmPsswd.Password.Length < 6)
                {
                    MessageBox.Show("The password lenght is less than 6 characters, please try again.");
                }

                else
                {
                    if (Psswd.Password == ConfirmPsswd.Password)
                    {
                        MessageBoxResult result = MessageBox.Show($"Are you sure do you want to create the user '{Name.Text} {lastName.Text}' with '{User.Text}'?", "Register", MessageBoxButton.YesNo);
                        switch (result)
                        {
                        case MessageBoxResult.Yes:
                            SqlCommand createUser = new SqlCommand("Insert Into UserInfo (Name, LastName, UserName, Balance, Password) Values" +
                                                                   " ('" + Name.Text + "','" + lastName.Text + "','" + User.Text + "', '0', '" + ConfirmPsswd.Password + "')", conn);
                            createUser.ExecuteNonQuery();
                            Operations_2 operations = new Operations_2();
                            conn.Close();
                            this.Close();
                            operations.ShowDialog();
                            break;

                        case MessageBoxResult.No:
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("The password doesn't match, make sure you have wrote it correctly.");
                    }
                }
            }
            conn.Close();
        }