Categories: .netasp.netc#

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ı
}

salih kiraz

View Comments

Recent Posts

Sürekli çalışan Android hizmeti geliştirmek

Sürekli çalışan Android hizmeti geliştirmek

3 yıl ago

Mssql veritabanından PostgreSql veritabanına geçiş notlarım

Yıllar önce MSSQL veritabanından PSQL veritabanına geçiş yaparken aldığım notları sizinle paylaşmak istedim . Umarım…

4 yıl ago

Minio Nesne Depolama Sunucusu(dosya sunucusu) Linux Ubuntu (18 -16 ) üzerinde kurulum

Dosyalarınızı farklı bir sunucu üzerinde barındırmaya karar vermişseniz minio ile karşılaşmısınızdır.Bende minio serveri kendi projelerimde…

4 yıl ago

Osticket Saml Eklentisi(Plugin)

Osticket 1.12.x ve 1..14.x sürümleri ile uyumulu olan Saml eklentisini github sayfamda yayınlamış bulunmaktayım.

4 yıl ago

WordPress yeni editörü(Gutenberg) blok oluşturma

Yeni WordPress editörü (Gutenberg) 5.0 sürümünde yayınlanmıştır. Şimdi WordPress çekirdeğine inmeden önce onunla başa çıkmanın tam…

5 yıl ago

Traefik ile sunucu yük dağılımı (Load balancing)

HaProxy ve Ngix ile suncuu yük dağılımı yapılabiliyor.Şimdi popüler olan araç ise Traefik ( Bu…

6 yıl ago