As others have mentioned, this can be caused by a few things.
I've experienced this error after a couple Ubuntu upgrades, and each time, it was because I was using the Nvidia driver, which didn't update properly update, was incompatible with the new kernel, and was causing the window manager to crash and bump me back to the login screen.
Unfortunately, how this manifests doesn't make this cause immediately obvious, and just looks like your password isn't working.
The following commands are how I fixed it. The general solution is to purge the old video driver, all config files that were customized by it, and then reinstall.
These exact commands probably won't work for you, but something like them might work if the cause is indeed a bad video driver.
sudo apt-get purge nvidia*
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install linux-headers-generic
sudo apt-get purge xserver-xorg-video-nouveau nouveau*
sudo nano /etc/modprobe.d/blacklist.conf # Add: blacklist nouveau
sudo rm -fr ~/.Xauthority
sudo rm -fr ~/.config/autostart
sudo apt-get remove --purge compiz
sudo apt-get install nvidia-settings
ubuntu-drivers devices # Find the recommended package for the video driver.
sudo apt-get install nvidia-340 # recommended by ubuntu-drives for me
sudo apt install gnome-shell
sudo apt autoremove
sudo reboot now