password_verify question

Discussion in 'PHP' started by scottlpool2003, Feb 6, 2014.

  1. #1
    I'm rewriting all of our scripts to use the PHP5.5 password_hash.

    My question is authenticating a user, I have to pull out the users hashed password before I can authenticate them. I've always been under the impression that it's bad practice to ever pull a password out regardless of if it's hashed.

    Am I missing something here?
     
    scottlpool2003, Feb 6, 2014 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Huh? you can do a query with the HASH of the entered password and compare it to the stored hash? never try to make a password from a hash... as it won't work!!
     
    EricBruggema, Feb 6, 2014 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    But if I hash it with password_hash, it creates a new hash and won't be the same as the one in the db?

    Here's where I'm at:

    
    <?php
    
    $statement = $dbconn->prepare("SELECT id, fname, sname, email, temppass, postcode, agerange, sex, regdate FROM users WHERE email = :email");
    $statement->execute([":email" => $_GET['email']]);
    
    $row = $statement->fetch(PDO::FETCH_ASSOC);
    if (password_verify($_GET['pass'],$row['pass'])){
       $message = [
                    "users" => [[
                        'id'        =>    $row['id'],
                        'fname'        =>    $row['fname'],
                        'sname'        =>    $row['sname'],
                        'email'        =>    $row['email'],
                        'temppass'    =>    $row['temppass'],
                        'postcode'    =>    $row['postcode'],
                        'agerange'    =>    $row['agerange'],
                        'sex'        =>    $row['sex'],
                        'regdate'    =>    $row['regdate']
                    ]]];
                echo json_encode($message);
      }else {
       $message = [
            "login" => [[
                "error"        =>    "Incorrect details"
            ]]];
       echo json_encode($message);
         
      }
    ?>
    
    PHP:
    I just don't like pulling that hashed password out but I'm not seeing any other way using password_verify...
     
    scottlpool2003, Feb 6, 2014 IP
  4. webshore88

    webshore88 Well-Known Member

    Messages:
    131
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #4
    You can store md5(password) in DB and can pull it out for password verification.
     
    webshore88, Feb 6, 2014 IP
  5. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #5
    Why would you store an MD5 password? Incredibly insecure...
     
    scottlpool2003, Feb 7, 2014 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Yeah, you gotta pull it. It's okay, but I wouldn't store it in a session or elsewhere after pulling it.
     
    nico_swd, Feb 7, 2014 IP
  7. webshore88

    webshore88 Well-Known Member

    Messages:
    131
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #7
    It is little confusing. Why MD5 password is more insecure than simple text password?
     
    webshore88, Feb 7, 2014 IP
  8. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #8
    He's using PHP's password_hash function, which is better than a simple MD5 hash. That's the reason he said it's less secure.
     
    bogi, Feb 7, 2014 IP