<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.OffScreen;
using Cookie = CefSharp.Cookie;

namespace SaltyBet_Desktop
{
    public partial class LoginForm : Form
    {
        private ChromiumWebBrowser browser;
        public LoginForm(ChromiumWebBrowser browser)
        {
            this.browser = browser;
            InitializeComponent();
        }

        private CookieContainer SendLoginRequest(string email, string password)
        {
            // Container for the cookies
            CookieContainer cookies = new CookieContainer();

            // Post data sent with request
            var postData = "email=" + email + "&pword=" + password;
            var data = Encoding.ASCII.GetBytes(postData);

            // Create a request using the POST data collected from saltybet
            var request = (HttpWebRequest) WebRequest.Create("http://www.saltybet.com/authenticate?signin=1");
            request.CookieContainer = cookies;
            request.Method = "POST";
            request.Referer = "http://www.saltybet.com/authenticate?signin=1";
            request.KeepAlive = true;
            request.ContentType = "application/x-www-form-urlencoded";
            // Write the post data to the request stream
            using (var stream = request.GetRequestStream())
                stream.Write(data, 0, data.Length);

            request.GetResponse();

            return cookies;
        }

        private void login(object sender, EventArgs e)
        {
            // Flush existing cookies
            Cef.GetGlobalCookieManager().DeleteCookiesAsync("http://www.saltybet.com/", "");

            CookieContainer cookies = SendLoginRequest(tbUsername.Text, tbPassword.Text);

            // Get the cookies for saltybet
            string[] cookieHeaders = cookies.GetCookieHeader(new Uri("http://www.saltybet.com")).Split(';');

            foreach (string i in cookieHeaders)
            {
                // Cookie name
                string name = i.Split('=')[0];
                // Value of cookie
                string value = i.Split('=')[1];

                Cookie cookie = new Cookie();
                cookie.Name = name;
                cookie.Domain = "www.saltybet.com";
                cookie.Creation = DateTime.Now;
                cookie.Value = value;<commit_msg>Refactored request data, closed stream<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.OffScreen;
using Cookie = CefSharp.Cookie;

namespace SaltyBet_Desktop
{
    public partial class LoginForm : Form
    {
        private ChromiumWebBrowser browser;
        public LoginForm(ChromiumWebBrowser browser)
        {
            this.browser = browser;
            InitializeComponent();
        }

        private CookieContainer SendLoginRequest(string email, string password)
        {
            // Container for the cookies
            CookieContainer cookies = new CookieContainer();

            // Post data sent with request
            var postData = "email=" + email + "&pword=" + password;
            var data = Encoding.ASCII.GetBytes(postData);

            // Create a request using the POST data collected from saltybet
            var request = (HttpWebRequest) WebRequest.Create("http://www.saltybet.com/authenticate?signin=1");
            request.CookieContainer = cookies;
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;
            request.AllowAutoRedirect = false;
            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36";
            // Write the post data to the request stream
            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
                stream.Close();
            }

            request.GetResponse();

            return cookies;
        }

        private void login(object sender, EventArgs e)
        {
            // Flush existing cookies
            Cef.GetGlobalCookieManager().DeleteCookiesAsync("http://www.saltybet.com/", "");

            CookieContainer cookies = SendLoginRequest(tbUsername.Text, tbPassword.Text);

            // Get the cookies for saltybet
            string[] cookieHeaders = cookies.GetCookieHeader(new Uri("http://www.saltybet.com")).Split(';');

            foreach (string i in cookieHeaders)
            {
                // Cookie name
                string name = i.Split('=')[0];
                // Value of cookie
                string value = i.Split('=')[1];

                Cookie cookie = new Cookie();
                cookie.Name = name;
                cookie.Domain = "www.saltybet.com";
                cookie.Creation = DateTime.Now;
                cookie.Value = value;
{'fraction_non_alphanumeric': 0.09901906348325004, 'fraction_numerical': 0.007033129742735517, 'mean_word_length': 2.0513833992094863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 11, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '96617', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1353, 'n_words': 353}