Read Captch Image value in the code

Feb 12, 2013 at 7:59 PM
Hi,

Is there a way to read Captcha Image value and user entered value in the textbox in code behind? I'm using this.IsCaptchaVerify("Captcha is not valid") method to validate at server side, but couldn't figure out what is shown and what user entered.

I could figure out little bit that it has alpha numeric value as
<input id="CaptchaDeText" name="CaptchaDeText" type="hidden" value="8a53e407d76c4cd98b589263cf279e25" />

Is it possible to decode back in readable format?
Coordinator
Feb 13, 2013 at 1:32 PM
Hi there,

The CaptchaDeText field doesn't contain a value of captcha, it contains a token for read real captcha value on the server side.
You can read value use this code:
var captchaManager = (DefaultCaptchaManager) CaptchaUtils.CaptchaManager;
ValueProviderResult tokenValue = ValueProvider.GetValue(captchaManager.TokenElementName);
ValueProviderResult inputText = ValueProvider.GetValue(captchaManager.InputElementName);
if (tokenValue == null)
    throw new ArgumentException("The ValueProvider does not contain a token value.");
if (inputText == null)
    throw new ArgumentException("The ValueProvider does not contain a captcha input value.");

//You can take a value for a token only once, the storage provider delete the value for the token.
ICaptchaValue captchaValue = captchaManager.StorageProvider.GetValidationValue(tokenValue.AttemptedValue);

//captchaValue.Value - contains value of captcha
//captchaValue.CaptchaText - contains text of captcha
//captchaValue.IsEqual(inputText.AttemptedValue) - determines whether the current captcha value is equal for the inputText.
Regards,
Vyacheslav Volkov
Feb 13, 2013 at 7:34 PM
Thanks Vyacheslav
Feb 11, 2016 at 12:27 AM
How do I get the CaptchaText?

<code>
var captchaManager = (DefaultCaptchaManager) CaptchaUtils.CaptchaManager;

ValueProviderResult tokenValue = ValueProvider.GetValue(captchaManager.TokenElementName);
ValueProviderResult inputText = ValueProvider.GetValue(captchaManager.InputElementName);
</code>

Both tokenValue and inputText are always null, however while drilling into the captchaManager Variable I can see the text equation.

The debugger shows this code that works in the watch window but not in the method I created.

<code>
((CaptchaMvc.Models.NumberCaptchaValue)new System.Collections.Generic.Mscorlib_DictionaryDebugView<CaptchaMvc.Models.KeyTimeEntry<string>, CaptchaMvc.Interface.ICaptchaValue>(((CaptchaMvc.Infrastructure.SessionStorageProvider)captchaManager.StorageProvider).ValidateKeys).Items[0].Value).CaptchaText
</code>


All help is appreciated.