PluginProbe ʕ •ᴥ•ʔ
FAPI Member / trunk
FAPI Member vtrunk
2.2.33 2.2.32 trunk 1.9.47 2.1.18 2.2.24 2.2.25 2.2.26 2.2.28 2.2.29 2.2.30 2.2.31
fapi-member / src / Utils / SecurityValidator.php
fapi-member / src / Utils Last commit date
AlertProvider.php 1 year ago ApiClient.php 1 day ago DateTimeHelper.php 1 year ago DateTimes.php 2 years ago DateTimesImmutable.php 2 years ago Debugger.php 1 year ago DisplayHelper.php 1 year ago EmailHelper.php 1 year ago PostTypeHelper.php 2 years ago Random.php 4 years ago SecurityValidator.php 2 years ago ShortcodeSubstitutor.php 2 months ago TemplateProvider.php 2 years ago functions.php 3 years ago
SecurityValidator.php
46 lines
1 <?php
2
3 namespace FapiMember\Utils;
4
5 final class SecurityValidator
6 {
7 public static function isInvoiceSecurityValid(
8 array $invoice,
9 int $time,
10 string $expectedSecurity
11 ): bool
12 {
13 $id = isset($invoice['id']) ? (int) $invoice['id'] : '';
14 $number = isset($invoice['number']) ? (int) $invoice['number'] : '';
15 $itemsSecurityHash = '';
16 $items = [];
17
18 if (isset($invoice['items']) && is_array($invoice['items'])) {
19 $items = $invoice['items'];
20 }
21
22 foreach ($items as $item) {
23 $itemsSecurityHash .= md5($item['id'] . $item['name']);
24 }
25
26 return $expectedSecurity === sha1($time . $id . $number . $itemsSecurityHash);
27 }
28
29 public static function isVoucherSecurityValid(
30 array $voucher,
31 array $itemTemplate,
32 int $time,
33 string $expectedSecurity,
34 ): bool
35 {
36 $voucherId = isset($voucher['id']) ? $voucher['id'] : '';
37 $voucherCode = isset($voucher['code']) ? $voucher['code'] : '';
38 $itemTemplateId = isset($itemTemplate['id']) ? $itemTemplate['id'] : '';
39 $itemTemplateCode = isset($itemTemplate['code']) ? $itemTemplate['code'] : '';
40 $itemSecurityHash = md5($itemTemplateId . $itemTemplateCode);
41
42 return $expectedSecurity === sha1($time . $voucherId . $voucherCode . $itemSecurityHash);
43 }
44
45 }
46