Comparing passwords with crypt() in PHP

前端 未结 6 1060
谎友^
谎友^ 2020-12-02 21:01

I need to get the basics of this function. The php.net documentation states, for the blowfish algorithm, that:

Blowfish hashing with a salt as follow

6条回答
  •  再見小時候
    2020-12-02 21:44

    New salt for every password

    $password = 'p@ssw0rd';
    
    $salt = uniqid('', true);
    $algo = '6'; // CRYPT_SHA512
    $rounds = '5042';
    $cryptSalt = '$'.$algo.'$rounds='.$rounds.'$'.$salt;
    
    $hashedPassword = crypt($password, $cryptSalt);
    // Store complete $hashedPassword in DB
    
    echo "
    $password
    $algo
    $rounds
    $cryptSalt
    $hashedPassword";

    Authentication

    if (crypt($passwordFromPost, $hashedPasswordInDb) == $hashedPasswordInDb) {
        // Authenticated
    

提交回复
热议问题