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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.