• Aijan@programming.devOP
    link
    fedilink
    arrow-up
    1
    arrow-down
    7
    ·
    9 days ago

    I appreciate the security concerns, but I wouldn’t consider overriding the password property with the hashed password to be wrong. Raw passwords are typically only needed in three places: user creation, login, and password reset. I’d argue that having both password and hashedPassword properties in the user object may actually lead to confusion, since user objects are normally used in hundreds of places throughout the codebase. I think, when applicable, we should consider balancing security with code maintainability by avoiding redundancy and potential confusion.

    • nous@programming.dev
      link
      fedilink
      English
      arrow-up
      9
      ·
      8 days ago

      When is the hashed password needed other than user creation, login or password resets? Once you have verified the user you should not need it at all. If anything storing it on the user at all is likely a bad idea. Really you have two states here - the unauthed user which has their login details, and an authed user which has required info about the user but not their password, hashed or not.

      Personally I would construct the user object from the request after doing auth - that way you know that any user object is already authed and it never needs to store the password or hash at all.

      • Aijan@programming.devOP
        link
        fedilink
        arrow-up
        1
        arrow-down
        2
        ·
        8 days ago

        Perhaps I was unclear. What I meant to say is that, whenever possible, we shouldn’t have multiple versions of a field, especially when there is no corresponding plaintext password field in the database, as is the case here.

        • nous@programming.dev
          link
          fedilink
          English
          arrow-up
          4
          ·
          8 days ago

          And they were arguing the same - just renaming the property rather than reusing it. You should only have one not both but naming them differently can make it clear which one you have.

          But here I am arguing to not have either on the user object at all. They are only needed at the start of a request and should never be needed after that point. So no point in attaching them to a user object - just verify the username and password and pass around user object after that without either the password or hash. Not everything needs to be added to a object.

    • Atlas_@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      9 days ago

      I absolutely agree. An even better structure wouldn’t have a raw password field on the user object at all.

    • Draugnoss@sopuli.xyz
      link
      fedilink
      arrow-up
      4
      ·
      9 days ago

      I agree. The field shouldn’t have been called ‘password’ in the first place, but rather ‘plaintextPassword’ or similar. That makes the code much more readable, if at a glance I know if I’m dealing with the hash or the plaintext version.