Completed
Push — master ( a206dc...d306f8 )
by Derek Stephen
02:37
created

EncryptableFieldEntity   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encryptField() 0 7 1
A verifyEncryptedFieldValue() 0 6 1
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
}