CGI: Authentication with ADS

Hi,

I'd like to write a cgi script with ruby, which generates a login page.
I have to use the active directory server for the authentication.

Do you have any hint how to do this? Do I have to use ruby's ldap library and compare any password hashes or is there a way to encrypt the password in a way that I can send it to the ADS and let him check it for validity? I've got no idea where to start. I've got knowledge about ldap, but still I don't know how to talk to the AS.

I have another script written in perl, which already solves this problem, but this scipt contains dozens of calls to system(). That's what I'd like to avoid, especially because the script should be portable to other unix version (where programs have different command line options, etc) and other operating systems.

thanks in advance

Boris