using gravatar in classic ASP

By | December 29, 2007

A gravatar is a globally recognized avatar, which means that your avatar is stored in one place and it will appear on several websites, blogs, forums (which support gravatars). Whenever you change your avatar it will be updated on your existing comments, forum posts, etc. It’s a great service! Now if you know what a gravatar is you might want to use it in one of your classic ASP applications. This post describes how to solve this simple problem…

Grabbing a gravatar is simple. It’s nothing more than writing a simple img-tag. The URL for the image points to the gravatar server and includes the email adress of the user whose avatar you want to display. Because everyone could simply grab the plain-text email from the html sourcecode we need to hash it with a MD5 hash. This keeps spammers away. Example of the html

  1. <img src="http://www.gravatar.com/avatar.php?gravatar_id=64b490fe11342e5662f54a9e20483fad" />

this example would show my personal gravatar which you should see on the left side. Now you have recognized that with classic ASP there is no built-in MD5 hasher. For this reason we need to use our own which you can download at the bottom of the post. Using our MD5 hasher we can easily generate gravatars from within ASP. Here is the code …

  1. <!--#include file="md5.asp"-->
  2. <%
  3. 'create an instance of our MD5 class
  4. set h = new MD5
  5. 'hash the email address we want the gravatar for
  6. hash = h.hash("someemail@somehost.com")
  7. 'provide an alternative image if no gravatar is available
  8. noPicUrl = server.urlEncode("http://yourhost.com/no_gravatar.gif")
  9. %>
  10. <img src="http://www.gravatar.com/avatar.php?gravatar_id=<%= hash %>&default=<%= noPicUrl %>" />

Finished! Thats all we need. There are other optional options which you could provide for the gravatar like e.g. the size of the gravatar. Get more details about the options here.

Download the classic ASP md5 hash class

For all of you who are looking for asp.net implementation of gravatar, please check Peter Bucher’s gravatar C# control. Unfortunately the article is in german, but source code speaks for itself ;)

21 comments on “using gravatar in classic ASP

  1. Little mistake:

    h = new MD5

    Should be:

    set h = new MD5

  2. or better yet:

    dim h:set h = new MD5
    :)

  3. Is there a way decrypt this?

    I would like to make a password system so I don’t have to buy a SSL certificate or use does hammered ones. I would like to encrypt the password (with javascript) with a public key that would be base on IP, date and hour (from server) plus password and ASP session. And decrypt on the next page to check if password is correct, since the ASP session is hard duplicate (I hope so), hour and date (from server). Someone can sniff the password and try to decrypt it, but with out the ASP Session correctly and use the encrypt password at the date and hour (with maybe a 10s interval), can not use the password. What do you think? Have you any experience with this?

  4. thanks rui for pointing out the mistake… blame on me :)
    regarding your decrypt questions: there is no decryption for MD5 hashes ..

  5. I thought that hashing “someemail@somehost.com” was for gravatar.com to decrypt or for the email spammers not get the email? So why hash the email then? Is it just to be a ID for gravatar.com, nothing more? Sorry if these are stupid questions.

  6. rui it would not make much sense if it would be possible to decrypt the email hash.. because the spammer would also do so then ;) gravatar knows your email addy and stores the md5 hash on their server too .. if you request a gravatar now with a hash, then they check if they have such a hash … thats the whole trick .. we achieve protection against spammers – which is the most important thing in this case.
    if u want to know something just ask ..

  7. thank you best and beatiful applications.

  8. Thank you for this code. I am using it right now in my blog.
    Oh, by the way, i am linking this tutorial in a post about it :D

    http://phillipecw.com/blog/template_permalink.asp?id=160

  9. jeffgator on said:

    thank you

  10. humphrey on said:

    thanks alot

  11. I can’t figure out why I’m getting the error in the MD5.asp file under the first line.. Class MD5

    Do I have the wrong version of vbScript? Help please…

  12. What a great code!
    Thank you very much!

  13. Its great! its ok

  14. It there any article about ASP.NET implementation, but in English? Thanks !!

  15. Hi Michal,

    Are you available to give me some help integrating this into my ASP blog, I have added the code as suggested, and added my own email address instead of someemail@somehost.com, it shows my image up for each comment entry now, im a little stuck, see demo below.

    Problem is getting the comment (persons) email to appear in each comment.

    http://www.sallysrescuecats.co.uk/simpleblog/?view=plink&id=6

    Rich

  16. owww thank you man ! i used that my projects

  17. Thank you your article.It will be great for us.

Leave a Reply

*

* Copy This Password *

* Type Or Paste Password Here *

49,905 Spam Comments Blocked so far by Spam Free Wordpress