private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            string name = UsernameBox.Text;
            string pw   = PasswordBox.Text;

            HashAlgorithm alg = MD5.Create();

            byte[] pwHash = alg.ComputeHash(Encoding.UTF8.GetBytes(pw));


            Database1TimerstuffTableAdapters.UserInfoTableAdapter ad = new Database1TimerstuffTableAdapters.UserInfoTableAdapter();
            ad.Connection = new SqlCeConnection(Properties.Settings.Default.Database1ConnectionString1);

            //"Data Source=\"C:\\Users\\Thad\\Documents\\Programming Practice\\Productivity Timer\\Productivity Timer\\Database1.sdf\""

            Database1Timerstuff timerstuff = new Database1Timerstuff();

            ad.Fill(timerstuff.UserInfo);

            try
            {
                ad.NewUserRow(name, pwHash);

                ad.Update(timerstuff);

                this.Close();
            }
            catch
            {
                MessageBox.Show("This username is already taken.");
            }
        }
Example #2
0
        private void SignInButton_Click(object sender, RoutedEventArgs e)
        {
            Database1Timerstuff ts = new Database1Timerstuff();

            Database1TimerstuffTableAdapters.UserInfoTableAdapter ad = new Database1TimerstuffTableAdapters.UserInfoTableAdapter();
            ad.Connection = new System.Data.SqlServerCe.SqlCeConnection("Data Source=\"C:\\Users\\Thad\\Documents\\Programming Practice\\Productivity Timer\\Productivity Timer\\Database1.sdf\"");

            ad.Fill(ts.UserInfo);

            HashAlgorithm alg = MD5.Create();

            alg.ComputeHash(Encoding.UTF8.GetBytes(PasswordBox.Text));

            byte[] pw = ad.GetPassword(UserNameBox.Text);

            byte[] pwHash = alg.Hash;



            if (pw.SequenceEqual(pwHash))
            {
                Username = UserNameBox.Text;

                this.DialogResult = true;
                this.Close();
            }
        }