Skip to content

Commit c55fa41

Browse files
author
Marcel Hauri
committed
obscure admin password to not exploit full password
1 parent 5c66125 commit c55fa41

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

Events/Admin/AdminUserAuthenticate.php

+37-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,32 @@
88

99
namespace Staempfli\ChatConnector\Events\Admin;
1010

11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\Event\ManagerInterface;
1113
use Magento\Framework\Event\Observer;
1214
use Magento\Framework\Event\ObserverInterface;
1315
use Staempfli\ChatConnector\Events\Events;
1416

1517
class AdminUserAuthenticate extends Events implements ObserverInterface
1618
{
19+
/**
20+
* @var \Magento\Framework\App\Request\Http
21+
*/
22+
private $request;
23+
24+
/**
25+
* AdminUserAuthenticate constructor.
26+
* @param RequestInterface $request
27+
* @param ManagerInterface $eventManager
28+
*/
29+
public function __construct(
30+
RequestInterface $request,
31+
ManagerInterface $eventManager
32+
) {
33+
parent::__construct($eventManager);
34+
$this->request = $request;
35+
}
36+
1737
/**
1838
* @param Observer $observer
1939
* @return void
@@ -22,10 +42,25 @@ public function execute(\Magento\Framework\Event\Observer $observer)
2242
{
2343
if (!$observer->getResult()) {
2444
$this->notify(__(
25-
"<strong>Admin user login failed!</strong>\n Username: %1 \n Password: %2",
45+
"<strong>Admin user login failed!</strong>\n Username: %1 \n Password: %2 \n IP: %3",
2646
$observer->getUsername(),
27-
$observer->getPassword()
47+
$this->getObscuredPassword($observer->getPassword()),
48+
$this->request->getServer('REMOTE_ADDR')
2849
));
2950
}
3051
}
52+
53+
/**
54+
* @param string $password
55+
* @return string
56+
*/
57+
private function getObscuredPassword(string $password)
58+
{
59+
$passwordLength = strlen($password);
60+
return sprintf('%s%s%s',
61+
substr($password, 0, 1),
62+
str_repeat('*', ($passwordLength - 2)),
63+
substr($password, -1)
64+
);
65+
}
3166
}

i18n/en_US.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
"<strong>Admin user login failed!</strong>\n Username: [%1] \n Password: [%2]","<strong>Admin user login failed!</strong>\n Username: [%1] \n Password: [%2]"
1+
"<strong>Admin user login failed!</strong>\n Username: %1 \n Password: %2 \n IP: %3","<strong>Admin user login failed!</strong>\n Username: %1 \n Password: %2 \n IP: %3"
22
"<strong>New Admin User was created!</strong>\n Username: %1 \n First Name: %2 \n Last Name: %3 \n E-Mail: %4","<strong>New Admin User was created!</strong>\n Username: %1 \n First Name: %2 \n Last Name: %3 \n E-Mail: %4"
33
"<strong>A new order has been placed.</strong>\n<strong>Order ID:</strong> %1\n<strong>Name:</strong> %2\n<strong>Subtotal:</strong> %3\n<strong>Shipping & Handling:</strong> %4\n <strong>Grand Total:</strong> %5","<strong>A new order has been placed.</strong>\n<strong>Order ID:</strong> %1\n<strong>Name:</strong> %2\n<strong>Subtotal:</strong> %3\n<strong>Shipping & Handling:</strong> %4\n <strong>Grand Total:</strong> %5"

0 commit comments

Comments
 (0)