1

I have created a database in my VS 2013 and added it as a datasource. VS have generated a class for my database and a method insert:

    private void registrationButton_Click(object sender, EventArgs e)
    {
        var adapter = new LogPassDataSetTableAdapters.TableTableAdapter();
        var table = new LogPassDataSet.TableDataTable();
        var data = adapter.GetData();
        MD5 md5 = new MD5CryptoServiceProvider();
        Form1 form1 = new Form1();

        var pass = passwordTextR.Text.ToString();
        byte[] result = md5.ComputeHash(Encoding.UTF8.GetBytes(pass));

        for (int i = 0; i <= data.Rows.Count; i++)
        {
            if (data.Rows.Count == 0)
            {
                adapter.Insert(logInTextR.Text.ToString(), BitConverter.ToString(result).Replace("-", string.Empty));
                MessageBox.Show("Registration complete");
                break;
            }
            else if (logInTextR.Text.ToString() == data[i].Login.ToString())
            {
                MessageBox.Show("This login already use");
                break;
            }
            else if (i == data.Rows.Count)
            {
                adapter.Insert(logInTextR.Text.ToString(), BitConverter.ToString(result).Replace("-", string.Empty));
                MessageBox.Show("Registration complete");
                break;
            }
        }

        this.Hide();
        form1.Show();
    }

This code doesn't fill the database. What is the problem? Can you help me with it?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Vlad
  • 154
  • 1
  • 2
  • 12
  • 1
    MD5 hashing to store password = BAD IDEA. See this answer about [Secure Hash and Salt for Passwords](http://stackoverflow.com/a/401684/945456) (the question is about PHP, but the same principles apply). Also this Jeff Atwood post called ["You're Probably Storing Passwords Incorrectly"](http://blog.codinghorror.com/youre-probably-storing-passwords-incorrectly/). – Jeff B Sep 12 '14 at 14:51

1 Answers1

0

I think that you should have this row after the insert statement:

adapter.Update(LogPassDataSet.TableDataTable);

Regards.