Completed
Push — master ( 9628d6...a206dc )
by Derek Stephen
09:38
created

EncryptableFieldEntity::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace OAuth\Traits;
4
5
use Zend\Crypt\Password\Bcrypt;
6
7
trait EncryptableFieldEntity
8
{
9
    private $bcrypt;
10
11
    public function __construct()
12
    {
13
        $this->bcrypt = new Bcrypt();
14
        $this->bcrypt->setCost(14);
15
    }
16
17
    /**
18
     * @param $value
19
     * @return bool|string
20
     */
21
    protected function encryptField($value)
22
    {
23
        $encryptedPassword = $this->bcrypt->create($value);
24
        return $encryptedPassword;
25
    }
26
27
    /**
28
     * @param $encryptedValue
29
     * @param $value
30
     * @return bool
31
     */
32
    protected function verifyEncryptedFieldValue($encryptedValue, $value)
33
    {
34
        return $this->bcrypt->verify($value, $encryptedValue);
35
    }
36
}