C# - jQuery 真人总是失败
C# - jQuery real-person allways fails
我使用 jQuery-realperson 插件。
但是,在服务器端验证验证码值总是失败。
我在 SO 看到了类似的问题,但这是关于 PHP 上发生的问题。
我需要 C# 代码。
我的客户端-js,基于knoskout.js:
var validCaptcha = $.ajax({
url: global.webApiConfig.getApiPath('Login/CheckCaptcha'),
data: { Value: $('#captcha').data().realperson.hash, PersonValue: $('#captcha').val() },
type: 'POST',
cache: false,
async: false
});
if (validCaptcha.responseText != true.toString()) {
vm.captchaError('invalid value');
refreshCaptcha();
return;
}
我的服务器端 - c#:
[HttpPost]
public bool CheckCaptcha(CaptachaData dataForCheck)
{
int hash = 5381;
dataForCheck.Value = dataForCheck.Value.ToUpper();
for (int i = 0; i < dataForCheck.Value.Length; i++)
{
hash = ((hash << 5) + hash) + dataForCheck.Value[i];
}
return dataForCheck.PersonValue != null && hash == dataForCheck.PersonValue.GetHashCode();
}
public class CaptachaData
{
public string Value { get; set; }
public string PersonValue { get; set; }
}
我想我发现了错误!
你得到 orignial-value- 的哈希码两次!
一次 - 在客户端:
$('#captcha').data().realperson.hash
还有一次-在服务器端:
dataForCheck.PersonValue.GetHashCode()
您需要在服务器端进行更改:
return dataForCheck.PersonValue != null && hash.ToString() == dataForCheck.PersonValue;
我使用 jQuery-realperson 插件。 但是,在服务器端验证验证码值总是失败。 我在 SO 看到了类似的问题,但这是关于 PHP 上发生的问题。 我需要 C# 代码。
我的客户端-js,基于knoskout.js:
var validCaptcha = $.ajax({
url: global.webApiConfig.getApiPath('Login/CheckCaptcha'),
data: { Value: $('#captcha').data().realperson.hash, PersonValue: $('#captcha').val() },
type: 'POST',
cache: false,
async: false
});
if (validCaptcha.responseText != true.toString()) {
vm.captchaError('invalid value');
refreshCaptcha();
return;
}
我的服务器端 - c#:
[HttpPost]
public bool CheckCaptcha(CaptachaData dataForCheck)
{
int hash = 5381;
dataForCheck.Value = dataForCheck.Value.ToUpper();
for (int i = 0; i < dataForCheck.Value.Length; i++)
{
hash = ((hash << 5) + hash) + dataForCheck.Value[i];
}
return dataForCheck.PersonValue != null && hash == dataForCheck.PersonValue.GetHashCode();
}
public class CaptachaData
{
public string Value { get; set; }
public string PersonValue { get; set; }
}
我想我发现了错误! 你得到 orignial-value- 的哈希码两次! 一次 - 在客户端:
$('#captcha').data().realperson.hash
还有一次-在服务器端:
dataForCheck.PersonValue.GetHashCode()
您需要在服务器端进行更改:
return dataForCheck.PersonValue != null && hash.ToString() == dataForCheck.PersonValue;