Jump to content

PHP Masking help


dennismonsewicz

Recommended Posts

I am trying to write a script that masks a users input when they submit a form and takes a field and is manipulated and then dumped into a database after being manipulated.

 

The mask will look like this:

 

nnn1n23nnnn4nn

 

Where n is a random number or letter and the '1234' will be the input from the user...

 

Any idea on how to achieve this?

Link to comment
https://forums.phpfreaks.com/topic/186215-php-masking-help/
Share on other sites

so this is what I came up with:

 

function maskStr($str = '') {
$characters = "1234567890abcdefghjkmnopqrstuvwxyz";

$explode = strtok($str, "");
$string_one = '';
$string_two = '';
$string_three = '';
$string_four = '';

for($a = 0; $a < 3; $a++) {
	$string_one .= $characters[mt_rand(0, strlen($characters) - 1)];
	$first = $string_one . $explode[0];
}

for($b = 0; $b < 1; $b++) {
	$string_two .= $characters[mt_rand(0, strlen($characters) - 1)];
	$second = $first . $string_two . $explode[1] . $explode[2];
}

for($c = 0; $c < 4; $c++) {
	$string_three .= $characters[mt_rand(0, strlen($characters) - 1)];
	$third = $second .  $string_three . $explode[3];
}

for($d = 0; $d < 2; $d++) {
	$string_four .= $characters[mt_rand(0, strlen($characters) - 1)];
	$final = $third . $string_four;
}

return $final;
}

echo maskStr('1234');

 

Is there anyway to make the above condensed or easier to look at it?

Link to comment
https://forums.phpfreaks.com/topic/186215-php-masking-help/#findComment-983469
Share on other sites

What is the point of this? It's hard to come up with a solution if you never tell us why you're manipulating a string in the first place like so. If you're trying to store a password, keycode or something of importance, than why not use hashing like it's meant to? md5

 

I'm not sure what the masking would be for at all..

Link to comment
https://forums.phpfreaks.com/topic/186215-php-masking-help/#findComment-983745
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.