The root cause is most likely on the server side. The fact that it works most of the time and occasionally throws a 500 error on login attempts is a clear indicator that it's not a problem on your side.
500