EncryptableFieldEntity::encryptField()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
}