iMac is stuck in a login loop

Boot to single user mode (hold cmdS while booting), delete the setup file and try making a new clean admin account.

/sbin/mount -uw /  
rm /var/db/.AppleSetupDone  
exit

At that point, assuming the OS is minimally functional, you can make a new admin account (call it test12345 or something to avoid hitting an existing user account) Optionally, you can delete the old user accounts and user home folders before you type exit above.

rm -rf /Users/whatever
rm /var/db/dslocal/nodes/Default/users/whatever.plist

Perform the two commands above for each user you want to remove from the system. You can also delete things more cleanly by logging in to your new admin account and deleting the old users from the graphical tool in system preferenes.