Google yeni recaptcha(2014) asp.net’te kullanımı
Sitenize googlenin yeni recaptcha(her seferinde nasıl yazılıyo diye baktığım kelime 😀 😀 ) daha kullanışlı olan 2014 model sürümü çıkmış bende asp.net ile uyumlu bir sürün bulamadım kendi entegre ettiğim kodları paylaşmaş istedim.
Detaylı bilgiyi aşağıdaki linkten bulabilirsiniz.
https://www.google.com/recaptcha/intro/index.html

(ben saksı değilim sürümünü merakla bekliyoruz 😀 😀 )
Bot dogrulama için fonksiyonlarmız
static string site_key = "sizin site keyiniz";
static string secret_key = "sizin secret keyiniz";
public static string botDogrulamaHtmlOlustur()
{
string html = @"<script type=""text/javascript"" src='https://www.google.com/recaptcha/api.js'></script>
<div class=""g-recaptcha"" data-sitekey=" + site_key + "></div>";
return html;
}
public static bool BotDogrulama()
{
string Response = HttpContext.Current.Request["g-recaptcha-response"];//Getting Response String Append to Post Method
bool Valid = false;
//Request to Google Server
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("https://www.google.com/recaptcha/api/siteverify?secret=" + secret_key + "&response=" + Response);
try
{
//Google recaptcha Response
using (System.Net.WebResponse wResponse = req.GetResponse())
{
using (StreamReader readStream = new StreamReader(wResponse.GetResponseStream()))
{
string jsonResponse = readStream.ReadToEnd();
System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
GoogleApiJsonModel data = js.Deserialize<GoogleApiJsonModel>(jsonResponse);// Deserialize Json
Valid = Convert.ToBoolean(data.success);
}
}
return Valid;
}
catch
{
return false;
}
}
public class GoogleApiJsonModel
{
public string success { get; set; }
}
Bot dogrulama sayfamız
öncelikle asp.net sayfamaza bir label eklememiz gerekiyor.bu labele dogrulama kdounu yerleştireceğiz
kod:
lbl_bot_dogrula.Text = botDogrulamaHtmlOlustur();
Bir adet butonuma ise formun doğrulandığını kontrol eden fonksişyonumuz yazıyoruz.Buton click olayına
Button1_Click
if(genelFonk.BotDogrulama()){
//doğrulama başarılı
}


Teşekkürler 🙂
Teşekkürler 🙂