DNS doesn't "verifies the password and username" but 504 Gateway errors do/could involve DNS.
There isn't a single fix ... must be investigated.
One can see several links.
Please see from the above Google search, this page (many are just like it):
While the next is about WordPress, what one does is almost the same for Moodle:
Where one is hosted, how hosted, in control of DNS or not, etc. makes a difference in more specific information.
Suggest contacting help desk of hosting provider for some assistance.
If using a Mac client/Linux client (can even run from your own server if Linux) ... try some curl test to your server.
Like: curl -vvv -I https://FQDNofYourMoodleSite/
include the /moodle/ directory if that's how you access your Moodle.
Do a 'dig' for your server: dig fqdnofmoodleserver
Do a reverse lookup on the IP address seen in the output of above:
dig -x IPADDRESS
Other things to check .... php max execution time, time zone correct?
Your web service errors logs.
'spirit of sharing', Ken