Exemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ClientID.Length != 0)
            {
                hash ^= ClientID.GetHashCode();
            }
            if (AppVersion.Length != 0)
            {
                hash ^= AppVersion.GetHashCode();
            }
            if (Language.Length != 0)
            {
                hash ^= Language.GetHashCode();
            }
            if (Channel.Length != 0)
            {
                hash ^= Channel.GetHashCode();
            }
            if (LighthouseId.Length != 0)
            {
                hash ^= LighthouseId.GetHashCode();
            }
            if (From != global::gen.msg.EntryPointFromType.Cdn)
            {
                hash ^= From.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ClientVer != 0)
            {
                hash ^= ClientVer.GetHashCode();
            }
            if (ClientID.Length != 0)
            {
                hash ^= ClientID.GetHashCode();
            }
            if (RecvNotify != false)
            {
                hash ^= RecvNotify.GetHashCode();
            }
            if (PacketEncAlgo != 0)
            {
                hash ^= PacketEncAlgo.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public override int GetHashCode()
        {
            int x = String.IsNullOrEmpty(ClientID) ? 0 : ClientID.GetHashCode();
            int y = Address == null ? 0 : Address.GetHashCode();

            int hash = 17;

            hash = hash * 31 + x;
            hash = hash * 31 + y;
            return(hash);
        }
    /// <summary>
    /// Returns a string of six random digits.
    /// </summary>
    private string GenerateRandomCode()
    {
        Random random = new Random(ClientID.GetHashCode() + (int)DateTime.Now.Ticks);

        string s = string.Empty;

        for (int i = 0; i < 6; i++)
        {
            s = String.Concat(s, random.Next(10).ToString());
        }

        return(s);
    }
    /// <summary>
    /// Returns a string of Count random digits.
    /// </summary>
    private string GenerateRandomCode()
    {
        var random = new Random(ClientID.GetHashCode() + (int)DateTime.Now.Ticks);

        var codes = new List <int>(Count);

        for (var i = 0; i < Count; i++)
        {
            codes.Add(random.Next(10));
        }

        return(string.Join(Separator, codes));
    }
Exemplo n.º 6
0
        public override int GetHashCode()
        {
            int hash = UserID.GetHashCode() ^ ClientID.GetHashCode() ^ IP.GetHashCode() ^ UdpPort.GetHashCode();

            if (TunnelClient != null)
            {
                hash = hash ^ TunnelClient.GetHashCode();
            }

            if (TunnelServer != null)
            {
                hash = hash ^ TunnelServer.GetHashCode();
            }

            return(hash);
        }
Exemplo n.º 7
0
    /// <summary>
    /// Returns a string of Count random digits.
    /// </summary>
    private string GenerateRandomCode()
    {
        Random random = new Random(ClientID.GetHashCode() + (int)DateTime.Now.Ticks);

        StringBuilder sb    = new StringBuilder();
        int           index = 1;

        for (int i = 0; i < Count; i++)
        {
            int randomNumber = random.Next(10);
            sb.Append(randomNumber);
            if (index < Count)
            {
                sb.Append(Separator);
            }
            index++;
        }

        return(sb.ToString());
    }
    /// <summary>
    /// Creates CAPTCHA question.
    /// </summary>
    private void CreateQuestion()
    {
        // Possible operations: + - * / < > =, plus same number of statements, plus same number of text and image possibilities
        string[] questions = new string[28];
        int      length    = 0;

        // If use text CAPTCHA
        if (!UseTextOrImageCaptcha)
        {
            // Add basic math operations
            if (UseMathOperations)
            {
                questions[length] = CHOICE_PLUS;
                length++;
                questions[length] = CHOICE_MINUS;
                length++;
            }

            // Add multiplication and dividing
            if (UseMultAndDiv)
            {
                questions[length] = CHOICE_MULT;
                length++;
                questions[length] = CHOICE_DIV;
                length++;
            }

            // Add compare operations
            if (UseCompareOperations)
            {
                questions[length] = CHOICE_SMALLER;
                length++;
                questions[length] = CHOICE_GREATER;
                length++;
                questions[length] = CHOICE_EQUAL;
                length++;
            }

            // Add statements
            if (UseStatements)
            {
                if (length == 0)
                {
                    questions[0] = CHOICE_STATEMENT;
                    length++;
                }
                else
                {
                    int countStatements = length * 2;
                    // Add same number of statements as number of operations
                    for (int i = length; i != countStatements; i++)
                    {
                        questions[i] = CHOICE_STATEMENT;
                        length++;
                    }
                }
            }
        }
        // Use image CAPTCHA
        else
        {
            if (length == 0)
            {
                questions[0] = CHOICE_IMAGE;
                length++;
            }
            else
            {
                int countImages = length * 2;
                for (int i = length; i != countImages; i++)
                {
                    questions[i] = CHOICE_IMAGE;
                    length++;
                }
            }
        }

        // Choose captcha
        Random random = new Random(ClientID.GetHashCode() + (int)DateTime.Now.Ticks);
        int    num    = random.Next(length);

        string choice = questions[num];

        // Prepare operands
        int    op1                 = random.Next(1, 10);
        int    op2                 = random.Next(1, 10);
        int    result              = 0;
        string chosenOperator      = string.Empty;
        string captchaQuestion     = string.Empty;
        string catpchaChoiceString = "error";

        // Generate chosen CAPTCHA
        switch (choice)
        {
        // Statements
        case CHOICE_STATEMENT:
            result = GetStatement(out captchaQuestion, random);
            if (result == -1)
            {
                return;
            }
            break;

        // Image CAPTCHA
        case CHOICE_IMAGE:
            result = GetImageQuestion(out captchaQuestion, random);
            break;

        // Math and compare operations
        case CHOICE_PLUS:
            result              = op1 + op2;
            chosenOperator      = "+";
            catpchaChoiceString = CHOICE_MATH_OPERATION;
            break;

        case CHOICE_MINUS:
            result              = op1 - op2;
            chosenOperator      = "-";
            catpchaChoiceString = CHOICE_MATH_OPERATION;
            break;

        case CHOICE_MULT:
            result              = op1 * op2;
            chosenOperator      = "*";
            catpchaChoiceString = CHOICE_MATH_OPERATION;
            break;

        case CHOICE_DIV:
            bool correct = true;
            while (correct)
            {
                // Swap numbers
                if (op1 < op2)
                {
                    int swap = op1;
                    op1 = op2;
                    op2 = swap;
                }
                // Check rest of division
                if ((op1 % op2) == 0)
                {
                    result  = op1 / op2;
                    correct = false;
                }
                // Generate new numbers
                else
                {
                    op1 = random.Next(1, 10);
                    op2 = random.Next(1, 10);
                }
            }

            chosenOperator      = "/";
            catpchaChoiceString = CHOICE_MATH_OPERATION;
            break;

        case CHOICE_EQUAL:
            result              = (op1 == op2) ? 1 : 0;
            chosenOperator      = "=";
            catpchaChoiceString = CHOICE_EQUAL;
            break;

        case CHOICE_SMALLER:
            result              = (op1 < op2) ? 1 : 0;
            chosenOperator      = "<";
            catpchaChoiceString = CHOICE_COMPARE;
            break;

        case CHOICE_GREATER:
            result              = (op1 > op2) ? 1 : 0;
            chosenOperator      = ">";
            catpchaChoiceString = CHOICE_COMPARE;
            break;

        default:
            break;
        }

        // Build CAPTCHA question
        if ((choice != CHOICE_STATEMENT) && (choice != CHOICE_IMAGE))
        {
            // Handle operands
            string strOp1 = op1.ToString();
            string strOp2 = op2.ToString();

            if (ConvertOperandsToText)
            {
                strOp1 = GetString("captcha." + strOp1);
                strOp2 = GetString("captcha." + strOp2);
            }

            // Handle operator
            if (ConvertOperatorToText)
            {
                chosenOperator = GetString("captcha." + choice);
            }

            captchaQuestion = String.Format(GetString("captcha.question." + catpchaChoiceString), chosenOperator, strOp1, strOp2);
        }

        // Store in session
        WindowHelper.Add("CaptchaImageText" + ClientID, result);
        SessionHelper.SetValue("CaptchaOperation" + ClientID, choice);

        lblQuestion.Text = GetString(captchaQuestion);

        // Image
        plcImage.Visible = (choice == CHOICE_IMAGE);
    }