Menu

#11 User.equals() method wrong

open
7
2002-06-04
2002-05-30
No

Consider the following two users:

Nickname: larry
Password: foobar
email: larry.berkowitz@seventiescop.org

Nickname: geoff
Password: foobar
email: geoff.geek@hacker.net

The equals method would return true because their
passwords are the same, when quite clearly they are two
separate users.

Discussion

  • Nigel Wetters Gourlay

    Logged In: YES
    user_id=104837

    is this a problem?

    equals() is used in two circumstances:

    1. when comparing whether passwords are equal between a user
    trying to log in under a particular nickname, and the
    version of that user object stored in the database (i.e.
    once we know the nickname, do the passwords match?)

    2. when comparing whether password are equal between a
    cookie showing a particular userID, and the version of that
    user object stored in the database (i.e. once we know the
    userID, do the passwords match?)

    What is the problem?

     
  • Nigel Wetters Gourlay

    • assigned_to: nwetters --> cwatana
     
  • Chris Watana

    Chris Watana - 2002-06-04
    • assigned_to: cwatana --> nwetters
     
  • Chris Watana

    Chris Watana - 2002-06-04

    Logged In: YES
    user_id=522688

    Just comparing passwords isn't really in the spirit of the
    equals method. It's just not robust. Who's going to remember
    that only passwords are compared in the future?

    Two solutions:
    1. Fix equals method (my preferred option)
    2. Make it clear that only passwords are being compared i.e.
    rename equals() equalPasswords() and explain circumstances
    in JavaDoc comments, just as you've explained it to me here.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.