コード例 #1
0
        public static CaptchaResponce validateCaptcha(string captchaAnswer, string publicKey)
        {
            CaptchaResponce responce = new CaptchaResponce();

            try
            {
                string decrypted1 = decryptStr(publicKey.Replace("~A", "="), captcahSalt, true);

                DateTime encryptedDate = DateTime.Parse(decrypted1.Split(new string[] { "$##$" }, StringSplitOptions.None)[1]);

                if ((DateTime.Now - encryptedDate).TotalMinutes < 5)
                {
                    string captchaAnswerDecrypted = decryptStr(decrypted1.Split(new string[] { "$##$" }, StringSplitOptions.None)[0], captcahSalt, true);

                    if (captchaAnswer.ToUpper() == captchaAnswerDecrypted.ToUpper())
                    {
                        responce.Correct = true;
                        responce.Text    = "Answer is correct";
                    }
                    else
                    {
                        responce.Correct = false;
                        responce.Text    = "Captcha answer does not match captcha";
                    }
                }
                else
                {
                    responce.Correct = false;
                    responce.Text    = "Captcha timeout occured";
                }
            }
            catch
            {
                responce.Correct = false;
                responce.Text    = "Captcha is not valid";
            }

            return(responce);
        }
コード例 #2
0
        public static CaptchaResponce validateCaptcha(string captchaAnswer, string publicKey)
        {
            CaptchaResponce responce = new CaptchaResponce();
            try
            {
                string decrypted1 = decryptStr(publicKey.Replace("~A", "="), captcahSalt, true);

                DateTime encryptedDate = DateTime.Parse(decrypted1.Split(new string[] { "$##$" }, StringSplitOptions.None)[1]);

                if ((DateTime.Now - encryptedDate).TotalMinutes < 5)
                {
                    string captchaAnswerDecrypted = decryptStr(decrypted1.Split(new string[] { "$##$" }, StringSplitOptions.None)[0], captcahSalt, true);

                    if (captchaAnswer.ToUpper() == captchaAnswerDecrypted.ToUpper())
                    {
                        responce.Correct = true;
                        responce.Text = "Answer is correct";
                    }
                    else
                    {
                        responce.Correct = false;
                        responce.Text = "Captcha answer does not match captcha";
                    }
                }
                else
                {
                    responce.Correct = false;
                    responce.Text = "Captcha timeout occured";
                }
            }
            catch
            {
                responce.Correct = false;
                responce.Text = "Captcha is not valid";
            }

            return responce;
        }