<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Collections;

namespace DTOperator
{
    class DBUtils
    {
        private static DBUtils instance = null;

        private SqlConnection conn = null;

        public static DBUtils GetInstnace()
        {
            if(instance == null)
            {
                instance = new DBUtils();
            }
            return instance;
        }

        private DBUtils()
        {
            conn = new SqlConnection("Server=127.0.0.1;Database=dtoperator_windows;Integrated Security=SSPI");
			conn.Open();
        }

		//check if an account is enabled
        public bool IsEnabled(String username)
        {
            if(username == null || username.Equals(""))
            {
                Console.WriteLine("is enabled on null or empty user name?");
                return false;
            }

            using (SqlCommand checkEnabled = new SqlCommand())
            {
                checkEnabled.CommandText = "select Enabled from Users where Username=@uname";
                checkEnabled.Parameters.AddWithValue("@uname", username);
                checkEnabled.CommandType = System.Data.CommandType.Text;
                checkEnabled.Connection = conn;

				try //public facing function that gets the user name. try/catch to prevent a malicious "user name" causing a fatal crash
				{
					using (SqlDataReader reader = checkEnabled.ExecuteReader())
					{
						if (reader.HasRows)
						{
							return (bool)reader["Enabled"];
						}
						return false;
					}
				}
				catch (Exception e)
				{
					WriteDBLog(new Log(Log.TAG_DBUTILS, "user: " + username + "\n" + e.Message + "\n" + e.StackTrace, Log.SELF, Log.ERROR, Log.SELFIP));
					return false;
				}
            }
        }

		//get a user's public key string dump
		public String GetDump(String username)
		{
			if (username == null || username.Equals(""))
			{
				Console.WriteLine("is enabled on null or empty user name?");
				return null;
			}

			using (SqlCommand checkEnabled = new SqlCommand())
			{
				checkEnabled.CommandText = "select Keydump from Users where Username=@uname";
				checkEnabled.Parameters.AddWithValue("@uname", username);
				checkEnabled.CommandType = System.Data.CommandType.Text;
				checkEnabled.Connection = conn;

				using (SqlDataReader reader = checkEnabled.ExecuteReader())
				{<commit_msg>Don't assume always db logging for db accounts<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Collections;

namespace DTOperator
{
    class DBUtils
    {
        private static DBUtils instance = null;

        private SqlConnection conn = null;

        public static DBUtils GetInstnace()
        {
            if(instance == null)
            {
                instance = new DBUtils();
            }
            return instance;
        }

        private DBUtils()
        {
            conn = new SqlConnection("Server=127.0.0.1;Database=dtoperator_windows;Integrated Security=SSPI");
			conn.Open();
        }

		//check if an account is enabled
        public bool IsEnabled(String username)
        {
            if(username == null || username.Equals(""))
            {
                Console.WriteLine("is enabled on null or empty user name?");
                return false;
            }

            using (SqlCommand checkEnabled = new SqlCommand())
            {
                checkEnabled.CommandText = "select Enabled from Users where Username=@uname";
                checkEnabled.Parameters.AddWithValue("@uname", username);
                checkEnabled.CommandType = System.Data.CommandType.Text;
                checkEnabled.Connection = conn;

				try //public facing function that gets the user name. try/catch to prevent a malicious "user name" causing a fatal crash
				{
					using (SqlDataReader reader = checkEnabled.ExecuteReader())
					{
						if (reader.HasRows)
						{
							return (bool)reader["Enabled"];
						}
						return false;
					}
				}
				catch (Exception e)
				{
					Logger.GetInstance().InsertLog(new Log(Log.TAG_DBUTILS, "user: " + username + "\n" + e.Message + "\n" + e.StackTrace, Log.SELF, Log.ERROR, Log.SELFIP));
					return false;
				}
            }
        }

		//get a user's public key string dump
		public String GetDump(String username)
		{
			if (username == null || username.Equals(""))
			{
				Console.WriteLine("is enabled on null or empty user name?");
				return null;
			}

			using (SqlCommand checkEnabled = new SqlCommand())
			{
				checkEnabled.CommandText = "select Keydump from Users where Username=@uname";
				checkEnabled.Parameters.AddWithValue("@uname", username);
				checkEnabled.CommandType = System.Data.CommandType.Text;
				checkEnabled.Connection = conn;

				using (SqlDataReader reader = checkEnabled.ExecuteReader())
				{
{'fraction_non_alphanumeric': 0.10021829728120658, 'fraction_numerical': 0.0023814248858900575, 'mean_word_length': 2.2516129032258063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3997702', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1351, 'n_words': 365}