예제 #1
0
        public static void AddCaptcha(IClient client)
        {
            if (list.Find(x => x.Guid.Equals(client.Guid)) != null)
            {
                return;
            }

            CaptchaRecord record = new CaptchaRecord
            {
                Guid = client.Guid,
                Time = (int)(uint)(Helpers.UnixTime - 1000000000)
            };

            list.Add(record);

            using (SQLiteConnection connection = new SQLiteConnection("Data Source=\"" + DataPath + "\""))
            {
                connection.Open();

                String query = @"insert into captchas (guid, time) values (@guid, @time)";

                using (SQLiteCommand command = new SQLiteCommand(query, connection))
                {
                    command.Parameters.Add(new SQLiteParameter("@guid", record.Guid.ToString()));
                    command.Parameters.Add(new SQLiteParameter("@time", record.Time));
                    command.ExecuteNonQuery();
                }
            }
        }
예제 #2
0
        public static bool HasCaptcha(IClient client)
        {
            CaptchaRecord record = list.Find(x => x.Guid.Equals(client.Guid));

            if (record != null)
            {
                int time = (int)(uint)(Helpers.UnixTime - 1000000000);

                if (record.Time < (time - 604800))
                {
                    record.Time = time;

                    using (SQLiteConnection connection = new SQLiteConnection("Data Source=\"" + DataPath + "\""))
                    {
                        connection.Open();

                        String query = @"update captchas set time=@time where guid=@guid";

                        using (SQLiteCommand command = new SQLiteCommand(query, connection))
                        {
                            command.Parameters.Add(new SQLiteParameter("@time", record.Time));
                            command.Parameters.Add(new SQLiteParameter("@guid", record.Guid.ToString()));
                            command.ExecuteNonQuery();
                        }
                    }
                }
            }

            return(record != null);
        }