first
This commit is contained in:
54
app/Support/SensitiveData.php
Normal file
54
app/Support/SensitiveData.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
class SensitiveData
|
||||
{
|
||||
public static function maskIc(?string $value): string
|
||||
{
|
||||
return self::mask($value, 4, 4);
|
||||
}
|
||||
|
||||
public static function maskAccount(?string $value): string
|
||||
{
|
||||
return self::mask($value, 3, 4);
|
||||
}
|
||||
|
||||
public static function maskPhone(?string $value): string
|
||||
{
|
||||
return self::mask($value, 3, 3);
|
||||
}
|
||||
|
||||
public static function maskName(?string $value): string
|
||||
{
|
||||
$normalized = trim((string) $value);
|
||||
|
||||
if ($normalized === '') {
|
||||
return '-';
|
||||
}
|
||||
|
||||
$length = mb_strlen($normalized);
|
||||
$visible = min(3, $length);
|
||||
|
||||
return mb_substr($normalized, 0, $visible).str_repeat('*', max(0, $length - $visible));
|
||||
}
|
||||
|
||||
private static function mask(?string $value, int $prefix, int $suffix): string
|
||||
{
|
||||
$normalized = trim((string) $value);
|
||||
|
||||
if ($normalized === '') {
|
||||
return '-';
|
||||
}
|
||||
|
||||
$length = mb_strlen($normalized);
|
||||
|
||||
if ($length <= ($prefix + $suffix)) {
|
||||
return str_repeat('*', $length);
|
||||
}
|
||||
|
||||
return mb_substr($normalized, 0, $prefix)
|
||||
.str_repeat('*', $length - $prefix - $suffix)
|
||||
.mb_substr($normalized, -$suffix);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user