Completed
Push — master ( a206dc...d306f8 )
by Derek Stephen
02:37
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
    /**
12
     * @param $value
13
     * @return bool|string
14
     */
15
    protected function encryptField($value)
16
    {
17
        $this->bcrypt = new Bcrypt();
18
        $this->bcrypt->setCost(14);
19
        $encryptedPassword = $this->bcrypt->create($value);
20
        return $encryptedPassword;
21
    }
22
23
    /**
24
     * @param $encryptedValue
25
     * @param $value
26
     * @return bool
27
     */
28
    protected function verifyEncryptedFieldValue($encryptedValue, $value)
29
    {
30
        $this->bcrypt = new Bcrypt();
31
        $this->bcrypt->setCost(14);
32
        return $this->bcrypt->verify($value, $encryptedValue);
33
    }
34
}