brstreet2/maskify

A PHP package for masking strings with customizable visibility.

dev-master 2025-05-11 05:27 UTC

This package is auto-updated.

Last update: 2025-05-11 05:30:06 UTC


README

Maskify is a lightweight PHP library designed to mask sensitive parts of a string with customizable visibility. This is particularly useful when working with sensitive data such as phone numbers, email addresses, or credit card numbers, which often need to be partially hidden for security or compliance purposes.

Motivation

As a backend developer, I’ve frequently encountered requests from frontend developers to return masked data in API responses. This inspired me to create a reusable and reliable solution that simplifies masking sensitive data without adding complexity to backend systems.

Some example use cases for Maskify:

  • Masking user phone numbers or email addresses in API responses.
  • Hiding sensitive information such as account numbers or credit card details.
  • Masking data during logging or debugging to protect sensitive values.

Features

  • Mask any string with asterisks (*).
  • Customize the number of visible characters at the start or end of the string.
  • Lightweight and easy to integrate with any PHP project.

Installation

Install the package via Composer:

composer require brstreet2/maskify

Usage

Here's how to use the Maskify package in your project:

Basic Usage

use Brstreet2\Maskify\Services\Masker;

$masker = new Masker();

// Mask a phone number, keeping the last 4 digits visible
echo $masker->mask('1234567890', 4); // Output: ******7890

Customizing Mask Length

// Mask an email address, keeping the first 3 characters visible
echo $masker->mask('example@gmail.com', -3); // Output: exa***********.com

Advanced Options

You can also mask a string completely:

echo $masker->mask('SensitiveData'); // Output: **************

Testing

Run tests to ensure everything is working as expected:

composer test

Contributing

Contributions are welcome! If you have ideas for new features or improvements, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.