/*
 * call-seq:
 *    PGconn.encrypt_password( password, username ) -> String
 *
 * This function is intended to be used by client applications that
 * send commands like: +ALTER USER joe PASSWORD 'pwd'+.
 * The arguments are the cleartext password, and the SQL name 
 * of the user it is for.
 *
 * Return value is the encrypted password.
 */
static VALUE
pgconn_s_encrypt_password(VALUE self, VALUE password, VALUE username)
{
        char *encrypted = NULL;
        VALUE rval = Qnil;

        Check_Type(password, T_STRING);
        Check_Type(username, T_STRING);

        encrypted = PQencryptPassword(StringValuePtr(password), StringValuePtr(username));
        rval = rb_str_new2( encrypted );
        PQfreemem( encrypted );

        OBJ_INFECT( rval, password );
        OBJ_INFECT( rval, username );

        return rval;
}