Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: We blame tye.

by mdillon (Priest)
on Mar 22, 2002 at 17:11 UTC ( #153607=note: print w/ replies, xml ) Need Help??


in reply to We blame tye.

Another lesson:

DO NOT STORE PASSWORDS AS PLAIN TEXT!

DO use something like crypt or Crypt::PasswdMD5!


Comment on Re: We blame tye.
Replies are listed 'Best First'.
Plaintext passwords?
by no_slogan (Deacon) on Mar 22, 2002 at 18:20 UTC
    Unfortunately, storing the crypted version of the password on the server means that the client has to send the password to the server in plaintext. Either you hide that with SSL, or you accept the fact that you have no real security.

    If you try to protect the password in transit by using something like HTTP digest authentication, then you have to store the password (or some equivalent secret information) in plaintext on the server. Which is the bigger vulnerability?

    And then there's the problem of forgotten passwords. If I forget mine, perlmonks will mail it to me. Not too secure, but handy. If you store crypted passwords, the only option is to reset them to some known value when they are forgotten. How do you know if the person requesting a reset of my password is me, or a bad guy?

      The way I typically handle it is to.
      • store them crypted
      • require that the login page be accessed via SSL
      • forgotten password is reset and emailed ONLY to the email address stored in the database for the provided user id. This doesn't prevent a malicious person from resetting someone else's password, BUT the person who receives the email saying what the new (randomly generated) password is, is the valid user.

      /\/\averick
      perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

        That all sounds good. I assume that once someone logs in successfully via SSL, you send them a cookie, and they continue using that over an unsecured connection? In that case, the cookie essentially becomes the user's password. Do you have a good solution for preventing the bad guys from capturing and reusing that cookie?

        Unfortunately, storing the crypted version of the password on the server means that the client has to send the password to the server in plaintext. Either you hide that with SSL, or you accept the fact that you have no real security.

        If you try to protect the password in transit by using something like HTTP digest authentication, then you have to store the password (or some equivalent secret information) in plaintext on the server. Which is the bigger vulnerability?

      Some excellent points, no_slogan. It's kind of depressing that the current state of the art, as far as anything common enough to be useful goes, relies so much on plaintext passwords. (Although you might be able to get the client to hash the password before sending it over the wire, using a browser plugin of some sort. Provided that you trust the plugin.)

      Is there a better way of doing user authentication for sites like PerlMonks out there that doesn't rely on pie-in-the-sky technology? (Preferably something that doesn't involve shared secrets, which IMHO are just too much trouble.) Having the client hash the password before sending it over the wire is a start, but doesn't help much if the server isn't who the client thinks it is, since the attacker can just play back the password hash at the real server.

      I'd look up some ideas, but my copy of Applied Crypto is at home, and I'm not. Anyone else?

      --
      :wq

        Having the client hash the password before sending it over the wire is a start, but doesn't help much if the server isn't who the client thinks it is, since the attacker can just play back the password hash at the real server.
        That's why HTTP digest authentication includes a variable "nonce" value. The server sends the nonce to the client when it first attempts to access the page. The client calculates the hash of the password and the nonce together, and sends that back to the server. The server verifies that the hash it recieved was calculated with a valid password and a nonce that was actually sent to that client recently.

        If someone tries to replay an old password hash, the server won't accept it, because it won't have a valid nonce.

        If the nonce used contains some (cryptographic) function of the time and the client's IP, you can avoid the problem of having to have the server remember which nonces are valid.

        The problem, of course, is that the server has to have the password in plaintext so it can calculate the hash and see if it matches the one it got from the client.

      I know I'm coming late to the dance with this, but I've been giving it some thought. When we speak of security, we are usually talking about one or two different things; authentication and encryption. The http protocol isn't really designed for security, it is designed for functionality. Security is left to the implementor.

      Putting aside https for the moment (which really is the best implementation of http when it comes to both of these topics) we need to look at what we can do to fulfill both of these points. In the case of a login, we are actually in the process of trying to authenticate our user, which means there isn't a trust system in place between the two parties.

      My thought about this would be that when a user first subscribes to our system, they are required to provide they're public key. Also, the monks public key is provided on the site. Now, when someone logs in, they first encrypt their pass-phrase (We're talking security here, so let's go all the way) with the monks public key, insert it into the pass-phrase text area and submit.

      PM has its private key, decrypts the pass-phrase and registers it. And, of course, monks must repeat this cycle if they must login. Of course we can still use our current cookie method of remembering who we are to limit the need for this. Beware, however, if we are at a location that doesn't have a tool for encryption, we won't be able to login. If a pass-phrase is lost, a new one can be generated and emailed to the monk using their public key. The system is complete.

      Another way would be to write an encryption method (using the above mentioned key structure) completely in JavaScript, send the PM public key in the client side scripting. OnSubmit, encrypt the pass-phrase, set one of your inputs (hidden or otherwise) to the encrypted password and away you go.

      Sounds trivial, but I'm not sure I would want to try and write those algorithms in JavaScript of VBScript. *BLECH*

      This brings me back to https. This protocol has the two pieces of security that I mentioned above. The authentication portion of https is a safeguard against some site saying they are PM when they're really not and stealing whatever informaiton we are sending to one another. The simplist method of encrypting passwords would be to implement the login only in https without a third party certificate. All we are truly talking about here is encrypting passwords and sending them securely, not authenticating one or both of the parties involved. On most webservers you can allow the server to generate it's own certificate for the sake of encryption, and only if we were going to implement a shopping cart or something similar would the need for a third party cert really be necessary.

      Those are just some thoughts I've had about this topic, your mileage may vary, this offer only good to the first ten callers, some restrictions may apply.

      C-.

        If a pass-phrase is lost, a new one can be generated and emailed to the monk using their public key.
        That would be really cool except for one little problem: what happens if I forget the password to my private key? I used to do that regularly, because I didn't decrypt messages very often.
        Now, when someone logs in, they first encrypt their pass-phrase with the monks public key, insert it into the pass-phrase text area and submit.
        You need to prevent someone from capturing and reusing my encrypted password, too. See my comment on nonces elsewhere in this thread.
        Of course we can still use our current cookie method of remembering who we are to limit the need for this.
        If you do this, my cookie essentially becomes my password, because anyone who has my cookie can make the system think he's me. Cookies are stored in plaintext on the user's computer. Cookies are sent across the network in plaintext. Not good for security.
        Beware, however, if we are at a location that doesn't have a tool for encryption, we won't be able to login.
        I think this is a deal-breaker for most web apps.
Re: Re: We blame tye.
by perrin (Chancellor) on Mar 22, 2002 at 18:42 UTC
    Unfortunately, many sites have to support a "mail me my password" feature. A tech site like this can get away with just sending people a new auto-generated password, but I don't think that, say, Amazon.com could do that. That means they must have the passwords in plain text somewhere.
      A tech site like this can get away with just sending people a new auto-generated password
      Then someone could hassle me by repeatedly requesting password changes on my account. If they did it every 5 minutes, I could hardly use the site at all. The server could impose a rate limit on password changes, like only one per day or so. That would eliminate the full-blown denial of service, but I'd still have to go check my e-mail for the new password, which might be inconvenient.
        This is true. I'm not sure there's a good way to deal with all possible attacks like this.

        As an aside, I often go to sites that have "mail me my password" features, request my password, and then realize I signed up under a different name. Then I wonder what the guy who just got the password reminder mail is thinking.

        To get around this, some sites ask the user for a hint question when they register. If the user forgets their password, they must answer their hint question (which they hopefully still remember), and supply some other personal information (which is verified against the info they provided upon registering). A new password is generated and emailed only if the above are correct. I'm pretty sure Yahoo does this for My Yahoo, Yahoo Mail, and the like.

        Another idea would be to generate a new password, but revert to the old one after, say, ten minutes if the user doesn't log in and change it. In this case, you would still let the user log in with the old password within those ten minutes. I realize this might not be easy to impliment ontop of an existing username/password database, though.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://153607]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2015-09-01 15:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred temperature scale is:










    Results (30 votes), past polls