Exemple #1
0
 public function verify($input, $existingHash)
 {
     if ($this->isMD5($existingHash)) {
         $md5 = new WeaveHashMD5();
         return $md5->verify($input, $existingHash);
     }
     $hash = crypt($input, $existingHash);
     return $hash === $existingHash;
 }
Exemple #2
0
        throw new Exception("bcrypt hash compare failed");
    }
    if (!$hash->needsUpdate(md5($pwd))) {
        throw new Exception("bcrypt hash needs update.");
    }
    if ($hash->needsUpdate('$2a$12$O2Bn6lDUYS5NDIJ1uCZjGezSI/jeGTD7Ow0bd3PFMRBcGIqfqI4Oi')) {
        throw new Exception("bcrypt hash doesn't needs update.");
    }
    if (!$hash->verify($pwd, 'a96b71c678b01b98b9f7a0d8ec4b633b')) {
        throw new Exception("bcrypt hash compare with md5 failed");
    }
    $hash2 = new WeaveHashBCrypt(6);
    if (!$hash2->needsUpdate('$2a$12$O2Bn6lDUYS5NDIJ1uCZjGezSI/jeGTD7Ow0bd3PFMRBcGIqfqI4Oi')) {
        throw new Exception("bcrypt hash needs update because of different rounds.");
    }
    $hashmd5 = new WeaveHashMD5();
    if (!$hashmd5->verify($pwd, 'a96b71c678b01b98b9f7a0d8ec4b633b')) {
        throw new Exception("md5 hash compare failed");
    }
    if (!$hashmd5->needsUpdate('$2a$12$O2Bn6lDUYS5NDIJ1uCZjGezSI/jeGTD7Ow0bd3PFMRBcGIqfqI4Oi')) {
        throw new Exception("md5 hash needs update.");
    }
    if ($hashmd5->needsUpdate(md5($pwd))) {
        throw new Exception("md5 hash doesn't need update.");
    }
    echo "all tests ok\n";
    exit(0);
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
    exit(1);
}