Feb 07

Akismet Spam Detection in .Net

A code sample for spam detection in .net using akismet api.

I finally got fed up with the amount of spam that is coming in through the comments form so decided to look into spam detection. It seems that Akismet is pretty much the standard for this. There is a .Net library that wraps around the Akismet API and I am pretty happy with how easy it was to get it hooked up.

Akismet api = new Akismet("AKISMET_API_KEY", "http://rickyrosario.com", "Ricky's Custom Blog/v1 | Akismet.Net 1.0.1");
AkismetComment c = new AkismetComment();
c.Blog = "http://rickyrosario.com";
c.UserIp = comment.AuthorIP;
c.UserAgent = comment.AuthorUserAgentString;
c.CommentContent = comment.Content;
c.CommentType = "comment";
c.CommentAuthor = comment.Author;
c.CommentAuthorEmail = comment.AuthorEmail;
c.CommentAuthorUrl = comment.AuthorUrl;

isSpam = api.CommentCheck(c);

if (!isSpam) {
   comment.IsRejected = false;
} else {
   comment.IsRejected = true;
}

Powered by my hackings on Django-Mingus a Django project, PostgreSQL, memcached, nginx, Apache + mod_wsgi, Ubuntu, Rackspace Cloud,...

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

html5 | top