iCloud sign in window keeps popping up despite being signed in
I reset my iCloud password about a year ago and i can sign in on my iMac and iPhone without a problem. But every time I turn on the iMac a small window pops up asking for the password and won't accept what I know is the correct one. If I go to iCloud in system preferences, which is set to automatically sign in, I can sign out and in no problem. Same if I go to iCloud.com.
I've gone through the whole process of putting in the verification code which was sent to my phone and the code was accepted. But the window is still popping up.
Can anyone help?
iMac, OS X Yosemite (10.10.5)