using gravatar in classic ASP

By | December 29

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="" />

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="<%= 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 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. Nice one.

    I had done a CustomControl implementation for .
    -

  2. Little mistake:

    h = new MD5

    Should be:

    set h = new MD5

  3. or better yet:

    dim h:set h = new MD5
    :)

  4. 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?

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

  6. I thought that hashing “someemail@somehost.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, nothing more? Sorry if these are stupid questions.

  7. 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 ..

  8. Also made one in januari …

  9. thank you best and beatiful applications.

  10. 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

  11. thank you

  12. thanks alot

  13. Thank !

  14. Awesome :D

  15. 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…

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

  17. Its great! its ok

  18. It there any article about implementation, but in English? Thanks !!

  19. 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 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.

    Rich

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

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