Hi,
Thank you very much for the info. It turns out that the problem was the 40 chars limit.
I was able to log in via SAPGui with the original password, which is longer than 40.
It seems that SAPGui ignores all characters after the first 40, that's why the long password worked with it but failed through RFC.