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

EncryptableFieldEntity   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

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