How do I determine where to place the foreign key in this scenario?
If I have two tables - logins and users, then:
Logins
LoginIdNo
UserIdNo
HashedPassword
Users
UserIdNo
LoginIdNo
Username
Every login "has a user" and every user "has a login" but which "owns" which?
Is this just a court call or is there a clearcut formula to determine where the foreign key should go?
a source to share
This is a one-to-one relationship. Where you put the foreign key is likely to determine the variance in these cases.
Is there any particular reason why you split this into two entities? I'm not a big fan of one-to-one mappings, especially in ORMs like JPA where it's awkward for them to implement (if you are using the primary key from one as a foreign key to the other).
What is the difference in your system between Login and User?
If the login should happen every time the user logs in (ie this is an audit trail of the user's activity), then you have a one-to-many relationship between the user and the Login, and Login should use the foreign key UserID ...
But in this case, when the username is in one table and the password is in the other, and a one-to-one relationship must be set between the two. You have to ask why they are separated.
a source to share
Since Login will never be associated with multiple Accounts (and vice versa), it is an arbitrary decision about how you define the relationship (and therefore where you place the foreign key). If you are not going to add other attributes (Firleds) or use roles, it would be easier to simply define them like this:
Users
UserIdNo
Username
HashedPassword
a source to share