1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Firesphere\HaveIBeenPwnd\Extensions; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\CheckboxField; |
6
|
|
|
use SilverStripe\Forms\FieldList; |
7
|
|
|
use SilverStripe\Forms\LiteralField; |
8
|
|
|
use SilverStripe\Forms\ReadonlyField; |
9
|
|
|
use SilverStripe\ORM\DataExtension; |
10
|
|
|
use SilverStripe\Security\Member; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class \Firesphere\HaveIBeenPwnd\Extensions\MemberExtension |
14
|
|
|
* |
15
|
|
|
* @property Member|MemberExtension $owner |
16
|
|
|
* @property int $PasswordIsPwnd |
17
|
|
|
* @property string $BreachedSites |
18
|
|
|
*/ |
19
|
|
|
class MemberExtension extends DataExtension |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private static $db = [ |
|
|
|
|
25
|
|
|
'PasswordIsPwnd' => 'Int', |
26
|
|
|
'BreachedSites' => 'Text' |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param FieldList $fields |
31
|
|
|
*/ |
32
|
|
|
public function updateCMSFields(FieldList $fields) |
33
|
|
|
{ |
34
|
|
|
// PwndDisabled always needs to be false |
35
|
|
|
$this->owner->PwndDisabled = false; |
|
|
|
|
36
|
|
|
|
37
|
|
|
$fields->removeByName(['BreachedSites', 'PasswordIsPwnd']); |
38
|
|
|
if ($this->owner->BreachedSites || $this->owner->PasswordIsPwnd) { |
39
|
|
|
$fields->findOrMakeTab('Root.HaveIBeenPwnd', _t(self::class . '.PWNDTAB', 'Have I Been Pwnd?')); |
40
|
|
|
} |
41
|
|
|
if ($this->owner->PasswordIsPwnd > 0 || $this->owner->BreachedSites) { |
42
|
|
|
$text = _t( |
43
|
|
|
self::class . '.PWNDHelp', |
44
|
|
|
'If the error says that you "have been Pwnd", it means your password appears in the <a href="https://haveibeenpwned.com/Privacy">Have I Been Pwnd</a> database. ' . |
45
|
|
|
'Therefore, we can not accept your password, because it is insecure or known to have been breached. ' . |
46
|
|
|
'Before a password is safely stored in our database, we test if the password has been breached. We do not share your password. ' . |
47
|
|
|
'We run a safe test against the HaveIBeenPwnd database to. None of your data is shared or stored at HaveIBeenPwnd. ' . |
48
|
|
|
'For more information, you can read up on "Password safety", and we strongly recommend installing a password manager if you haven\'t already. ' . |
49
|
|
|
'Several options are LastPass, BitWarden and 1Password. These services are also able to test your passwords against the HaveIBeenPwnd database, ' . |
50
|
|
|
'to see if your passwords are secure and safe.<br />' . |
51
|
|
|
'Furthermore, <a href="https://www.troyhunt.com/introducing-306-million-freely-downloadable-pwned-passwords/">Troy Hunt explains why and how this service is important</a>.' |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$help = LiteralField::create('Helptext', '<p>' . $text . '</p>'); |
55
|
|
|
$fields->addFieldToTab('Root.HaveIBeenPwnd', $help); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ($this->owner->BreachedSites) { |
59
|
|
|
$fields->addFieldToTab( |
60
|
|
|
'Root.HaveIBeenPwnd', |
61
|
|
|
ReadonlyField::create('BreachedSites', _t(self::class . '.BREACHEDSITES', 'Breached sites')) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$fields->addFieldToTab('Root.Main', $countField = ReadonlyField::create('PasswordIsPwnd', 'Pwnd Count')); |
66
|
|
|
$countField->setDescription(_t( |
67
|
|
|
self::class . '.AMOUNT', |
68
|
|
|
'Amount of times the password appears in the Have I Been Pwnd database' |
69
|
|
|
)); |
70
|
|
|
|
71
|
|
|
$fields->addFieldToTab('Root.Main', $tmpDisable = CheckboxField::create('PwndDisabled', _t(self::class . '.TMPDISABLE', 'Disable "Have I Been Pwnd" temporarily'))); |
72
|
|
|
$tmpDisable->setDescription(_t(self::class . '.TMPDISABLEDESCR', 'Allow the password to be a compromised password once (only from the CMS), to reset a users password manually and let the user reset the password on first login.')); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|