public bool CheckResult(int captchaId, string dataString) { bool result = false; int totalCaptchaTileCount = 0; CaptchaAttributes captchaAttributes = new CaptchaAttributes(); CaptchaSession captchaSession = new CaptchaSession(); captchaSession = captchaSession.GetCaptchaSession(captchaId); if (captchaSession.IsValid) { captchaAttributes = captchaAttributes.GetCaptchaAttribute_ById(captchaId); var singleImageString = dataString.Split(';'); for (int i = 0; i < singleImageString.Length; i++) { if (String.IsNullOrWhiteSpace(singleImageString[i])) { break; } // CODE OPTIMIZATION HERE if (i == 0 || result) { var imageKVP = singleImageString[i].Split('='); short currentDegree = Convert.ToInt16(imageKVP[1]); switch (imageKVP[0]) { case "captcha-1": totalCaptchaTileCount++; result = isImageDegreeCorrect(currentDegree, captchaAttributes.Tile1Angle); break; case "captcha-2": totalCaptchaTileCount++; result = isImageDegreeCorrect(currentDegree, captchaAttributes.Tile2Angle); break; case "captcha-3": totalCaptchaTileCount++; result = isImageDegreeCorrect(currentDegree, captchaAttributes.Tile3Angle); break; case "captcha-4": totalCaptchaTileCount++; result = isImageDegreeCorrect(currentDegree, captchaAttributes.Tile4Angle); break; case "captcha-5": totalCaptchaTileCount++; result = isImageDegreeCorrect(currentDegree, captchaAttributes.Tile5Angle); break; case "captcha-6": totalCaptchaTileCount++; result = isImageDegreeCorrect(currentDegree, captchaAttributes.Tile6Angle); break; case "captcha-7": totalCaptchaTileCount++; result = isImageDegreeCorrect(currentDegree, captchaAttributes.Tile7Angle); break; case "captcha-8": totalCaptchaTileCount++; result = isImageDegreeCorrect(currentDegree, captchaAttributes.Tile8Angle); break; case "captcha-9": totalCaptchaTileCount++; result = isImageDegreeCorrect(currentDegree, captchaAttributes.Tile9Angle); break; } } } // Update the captcha to invalid regardless of result captchaSession.UpdateIsValid(captchaId, false); captchaSession.DeleteCaptchaMoreThanOneDay(); //DeleteCaptchaImage(captchaId); } // If all 9 captcha tiles has not been verified if (totalCaptchaTileCount != 9) { result = false; } return(result); }