Esempio n. 1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (Valide(tb1.Text, tb2.Text, tb3.Text))
            {
                string ipv4 = NetworkHandler.GetLocalIP();
                string salt = CommonHandler.Get_salt();
                conn.Open();

                SqlCommand cmd = new SqlCommand("insert into user_info(username,salt,hash,status,ip,answer) values(@UN, @SALT, @HASH,0,@IP,@AS)", conn);
                cmd.Parameters.Add("@UN", SqlDbType.VarChar, 50).Value   = tb1.Text;
                cmd.Parameters.Add("@SALT", SqlDbType.VarChar, 50).Value = salt;
                cmd.Parameters.Add("@HASH", SqlDbType.VarChar, 50).Value = CommonHandler.Get_hash(tb2.Text, salt);
                cmd.Parameters.Add("@IP", SqlDbType.VarChar, 50).Value   = ipv4;
                cmd.Parameters.Add("@AS", SqlDbType.VarChar, 50).Value   = tb4.Text;

                cmd.ExecuteNonQuery();
                cmd.Dispose();

                Bitmap bitmap = new Bitmap("../../Image/default_avatar.png");
                bitmap = (Bitmap)CommonHandler.ResizeImage(bitmap, new Size(75, 75));
                string avatarStr     = CommonHandler.ImgToBase64String(bitmap);
                string backgroundStr = CommonHandler.ImgToBase64String("../../Image/default_background.png");

                SqlCommand insert = new SqlCommand("insert into user_picture (username, user_avatar, user_background) values(@UN, @UA, @UB)", conn);
                insert.Parameters.Add("@UN", SqlDbType.VarChar).Value = tb1.Text;
                insert.Parameters.Add("@UA", SqlDbType.VarChar).Value = avatarStr;
                insert.Parameters.Add("@UB", SqlDbType.VarChar).Value = backgroundStr;

                insert.ExecuteNonQuery();
                insert.Dispose();

                conn.Close();

                MessageBox.Show("Register successfully!", "STATE");

                To_HomePage(tb1.Text);
            }
        }