For me the caps lock solution didn't work.
But I noticed that my MacBook freezes often when there is a wifi network around that I have connected to in the past.
So the solution for me is to go somewhere that there is no wifi network or nothing that I connected to before. And then when I'm able to login, if I want to shut down or sleep my MacBook, I disable wifi first..
It's very odd and annoying, but it works!