Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a problem , when user enter the input, where should I save the data? I'm already connect the sqlite but I'm not sure how to save the input.Let focus on how to create login page. I have a connection.xaml.cs and login.xaml.cs. So this is my problem. Below is the connection.xaml.cs.If possible, give me a link that i can refer and study. I am beginner in sqlite. Thank You.

C#
SQLiteConnection sqlite_conn;
           SQLiteCommand sqlite_cmd;
           SQLiteDataReader sqlite_datareader;

            // create a new database connection:
           sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");

           // open the connection:
           sqlite_conn.Open();

           // create a new SQL command:
           sqlite_cmd = sqlite_conn.CreateCommand();

           // Let the SQLiteCommand object know our SQL-Query:
         sqlite_cmd.CommandText = "CREATE TABLE Login (id integer primary key, username varchar(50),password varchar(50));";

           // Now lets execute the SQL ;D
           sqlite_cmd.ExecuteNonQuery();

           // Lets insert something into our new table:
          sqlite_cmd.CommandText = "INSERT INTO Login (id,username,password) VALUES (111043, 'zakira' ,'abc123');";

           // And execute this again ;D
           sqlite_cmd.ExecuteNonQuery();

          sqlite_cmd.CommandText = "SELECT * FROM Login";

           // Now the SQLiteCommand object can give us a DataReader-Object:
           sqlite_datareader = sqlite_cmd.ExecuteReader();
        while (sqlite_datareader.Read())
          {
              string Myreader = sqlite_datareader.GetString(0);
              string Myreader2 = sqlite_datareader.GetString(1);
              string Myreader3 = sqlite_datareader.GetString(2);
              MessageBox.Show(Myreader + " " + Myreader2 + " " + Myreader3);
          }
// We are ready, now lets cleanup and close our connection:
          sqlite_conn.Close();
      }
Below is my Login.cs.xaml (login page). This is what i'm already done

C#
private void button1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Dalam Login button");
            string query = "select from  (Login) where password='" + textBox2.Text + "'";

            ExecuteQuery(query);
            SQLiteDataReader dr = sqlite_cmd.ExecuteReader();
            int count = 0;
            //string password = "";
            while (dr.Read())
            {

                count++;
            }
            if (count == 1)
            {
                MessageBox.Show("Logged In ");


            }
            else

                MessageBox.Show("Wrong Password :(");
  }

        private void textBox2_TextChanged(object sender, TextChangedEventArgs e)
        {
           // textBox2.password = '$';
            //dynamicTextBox.ShortcutsEnabled = false;
            var textBox = sender as TextBox;
        }
    }
Posted
Updated 24-Feb-15 23:49pm
v2
Comments
Richard MacCutchan 25-Feb-15 6:32am    
What is the problem?
Member 11175029 26-Feb-15 5:38am    
i would like to create login page. Below is in the table Login.The password is abc123. So how to check when user enter the password and it same.
"INSERT INTO Login (id,username,password) VALUES (111043, 'zakira' ,'abc123');";
Richard MacCutchan 26-Feb-15 5:53am    
Follow Richard Deeming's advice below. You need to spend some time learning how to store userids and passwords securely. When the user enters their details you should create a hash in the same way as when the user first registers, and then read the information from the database and check the values match.
Richard Deeming 25-Feb-15 9:27am    
It looks like you're storing passwords in plain text. That's a terrible idea! You should only ever store a salted hash of the password.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
Member 11175029 26-Feb-15 5:46am    
I think because it not read from the login table. This is my problem. it is possible if i put the Textbox2.Text during insert value. Means that, when user enter input, it will save and read that input.

1 solution

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900