"라라벨 BcryptHasher"의 두 판 사이의 차이

(새 문서: ==개요== ;라라벨 BcryptHasher <source lang='php'> <?php namespace Illuminate\Hashing; use RuntimeException; use Illuminate\Contracts\Hashing\Hasher as HasherContract; class...)
 
55번째 줄: 55번째 줄:
* [[라라벨 RuntimeException]]
* [[라라벨 RuntimeException]]
* [[라라벨 Hasher]]
* [[라라벨 Hasher]]
* [[PHP password_hash()]]


[[분류: Illuminate\Hashing]]
[[분류: Illuminate\Hashing]]

2016년 8월 22일 (월) 16:25 판

1 개요

라라벨 BcryptHasher
<?php

namespace Illuminate\Hashing;

use RuntimeException;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;

class BcryptHasher implements HasherContract
{
    protected $rounds = 10;

    public function make($value, array $options = [])
    {
        $cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;

        $hash = password_hash($value, PASSWORD_BCRYPT, ['cost' => $cost]);

        if ($hash === false) {
            throw new RuntimeException('Bcrypt hashing not supported.');
        }

        return $hash;
    }

    public function check($value, $hashedValue, array $options = [])
    {
        if (strlen($hashedValue) === 0) {
            return false;
        }

        return password_verify($value, $hashedValue);
    }

    public function needsRehash($hashedValue, array $options = [])
    {
        $cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;

        return password_needs_rehash($hashedValue, PASSWORD_BCRYPT, ['cost' => $cost]);
    }

    public function setRounds($rounds)
    {
        $this->rounds = (int) $rounds;

        return $this;
    }
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}