|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helmut\Forms\Fields\Password; |
|
4
|
|
|
|
|
5
|
|
|
use Helmut\Forms\Field; |
|
6
|
|
|
use Helmut\Forms\Utility\Validate; |
|
7
|
|
|
|
|
8
|
|
|
class Password extends Field { |
|
9
|
|
|
|
|
10
|
|
|
public $value = ''; |
|
11
|
3 |
|
|
|
12
|
|
|
public function hash($value) |
|
13
|
3 |
|
{ |
|
14
|
1 |
|
if (strlen($value) === 0) { |
|
15
|
|
|
return ''; |
|
16
|
|
|
} |
|
17
|
3 |
|
|
|
18
|
|
|
return password_hash($value, PASSWORD_BCRYPT, ['cost' => 10]); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function needsRehash($hash = null) |
|
22
|
|
|
{ |
|
23
|
|
|
if (is_null($hash)) $hash = $this->value; |
|
24
|
|
|
|
|
25
|
|
|
return password_needs_rehash($hash, PASSWORD_BCRYPT, ['cost' => 10]); |
|
26
|
|
|
} |
|
27
|
1 |
|
|
|
28
|
|
|
public function matches($hash) |
|
29
|
1 |
|
{ |
|
30
|
1 |
|
if (strlen($hash) === 0) { |
|
31
|
|
|
return false; |
|
32
|
|
|
} |
|
33
|
1 |
|
|
|
34
|
|
|
$check = $this->form->getRequest()->get($this->name); |
|
35
|
1 |
|
|
|
36
|
|
|
return password_verify($check, $hash); |
|
37
|
|
|
} |
|
38
|
5 |
|
|
|
39
|
|
|
public function getValue() |
|
40
|
5 |
|
{ |
|
41
|
|
|
return $this->value; |
|
42
|
|
|
} |
|
43
|
3 |
|
|
|
44
|
|
|
public function getButtonName() |
|
45
|
3 |
|
{ |
|
46
|
|
|
// |
|
47
|
|
|
} |
|
48
|
10 |
|
|
|
49
|
|
|
public function renderWith() |
|
50
|
10 |
|
{ |
|
51
|
|
|
// |
|
52
|
|
|
} |
|
53
|
10 |
|
|
|
54
|
|
|
public function setValueFromDefault() |
|
55
|
|
|
{ |
|
56
|
10 |
|
// |
|
57
|
|
|
} |
|
58
|
1 |
|
|
|
59
|
|
|
public function setValueFromModel($model) |
|
60
|
1 |
|
{ |
|
61
|
1 |
|
if (property_exists($model, $this->name)) $this->value = $model->{$this->name}; |
|
62
|
|
|
} |
|
63
|
3 |
|
|
|
64
|
|
|
public function setValueFromRequest($request) |
|
65
|
3 |
|
{ |
|
66
|
3 |
|
$this->value = $this->hash($request->get($this->name)); |
|
67
|
|
|
} |
|
68
|
4 |
|
|
|
69
|
|
|
public function fillModelWithValue($model) |
|
70
|
4 |
|
{ |
|
71
|
4 |
|
if (property_exists($model, $this->name)) $model->{$this->name} = $this->value; |
|
72
|
|
|
} |
|
73
|
1 |
|
|
|
74
|
|
|
public function validateRequired() |
|
75
|
1 |
|
{ |
|
76
|
|
|
return Validate::required($this->value); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |