-
Posts
1,943 -
Joined
-
Last visited
Never
Posts posted by discomatt
-
-
I'll send you $50 over PayPal if you tell me what the what the plaintext value I used for this hash is:
9f65f29197e64cef1f862f359866c3abdc473da40a0efd1f6bca32fb13cfb5da
It's not enough finding a string that matches the hash. You must prove that what you got is the same as what I originally had. Anyone else who wants to try can claim the $50 as well.
May I have 5.2^114 guesses?
-
-
I've always liked this method:
Generate random salt ( usually of the same length as the hash )
Chop the password and salt into 2 chunks.
Mix chunks and hash.
Split hash into 2 parts, mix with salt.
You now have the salt stored in plain text, but it's theoretically impossible to extract it from the hash without knowing the chunk sizes and algorithm used. It's a little paranoid, but it's actually a very light script ( php is very quick and string manip ) requiring only 1 hash to check a password.
Salting is VERY VERY important. I would argue a random salt is equally important. You're protecting your viewers passwords they might use elsewhere. Rainbow tables are becoming huge and easy to access.
-
That's another neat concept, but that one is a hog, running about 10x slower than our previous functions using realistic depth, and nearly 15x slower than mine on unrealistic depths.
I think I'm going to stick with either your or my original function, pending a little more speed testing.
Thanks again for the time and thought, and helping me look outside the box
-
You're better off using MySQL's timestamp type column...
-
I think the issue is the end user typing in double stars. Your best bet is to match \*++ in the regex that does the conversion.
-
That works great! Neat way of doing it.
Speed wise, the functions are near equal in real-life situations... I did trials using random data with an average depth ~5 and my function edged out yours by a negligible time. When doing unrealistic trials ( average depth ~100 ) your function ran about 3x faster than mine.
Thanks for the help sasa!
-
Here's a working example of what I'm doing on a broader scope
<pre><?php /* 1 67 20 107 43 116 77 153 125 161 */ $data = <<<DATA {loop} Some data {loop} Nested data {loop} More nests! {/loop} {loop} Another deep nest {/loop} {/loop} {loop} Not quite so deep {/loop} {/loop} {loop} More data {loop} Foobar {/loop} {loop} Warmer {loop} Waaaarmer {loop} Too hot! {/loop} {/loop} {/loop} {loop} More depth {loop} this is getting stupid {/loop} {/loop} {/loop} DATA; $pairs = getPairs($data, '{loop}', '{/loop}'); foreach( $pairs as $pair ) echo substr( $data, $pair[0], $pair[1]-$pair[0] ) . "\n\n\n--------\n\n\n"; function getPairs( $data, $openTag, $closeTag ) { // Grab opening and closing offsets $opening = getOffsets( $data, $openTag ); $closing = getOffsets( $data, $closeTag, FALSE ); // Verify proper formatting if( ($size = count($opening)) !== count($closing) ) die( "Invalid syntax detected" ); // Placeholder $offsets = array(); // Separate nests for( $i = 1; $i < $size; $i++ ) { // Set initial nest key static $last = 0; // Check to see if a new nest has begun if( isset($opening[$i+1]) === FALSE || $opening[$i+1] > $closing[$i] ) { // Send nest to parser and gather results $offsets = array_merge( $offsets, parseNest(array_slice($opening,$last,$i-$last+1), array_slice($closing,$last,$i-$last+1)) ); // Update nest key to the start of the next nest $last = $i+1; } } return $offsets; } function getOffsets( $data, $tag, $open = TRUE ) { // Placeholder $return = array(); // Start at beginning of string $offset = 0; // Loop through string grabbing offsets while( ($c = strpos($data, $tag, $offset)) !== FALSE ) { // Update search offset $offset = strpos( $data, $tag, $c ) + 1; // Remove tag offset and add to placeholder $return[] = $offset - 1 + ( $open == TRUE ? strlen($tag) : -1 ); } return $return; } function parseNest( $opening, $closing ) { // Placeholder $pairs = array(); // Loop through $opening backwards foreach( array_reverse($opening) as $oVal ) { /***** THIS IS THE CHUNK I THINK CAN BE IMPROVED ON *****/ // Loop through $closing until we find a value less than the current $opening foreach( $closing as $cKey => $cVal ) // Check to see if the current opening is less than the current closing if( $oVal < $cVal ) { // If so, add it to the pairs $pairs[] = array( $oVal, $cVal ); // Unset used value of b - prevents duplication and should speed things up unset( $closing[$cKey] ); // Break out of the loop break; } /***** END OF CHUNK *****/ } // Return them in ascending order return array_reverse( $pairs ); } ?></pre>
-
Zegan, I'm not exactly sure what you're doing... but your solution seems, well, overly complex?
Also, you should never use
for ($i=0; $i <count($a); $i++)
Unless you expect count($a) to change.
You should instead use
for ($i=0, $c=count($a); $i < $c; ++$i)
-
Okay, let me expand on this.
It's a function to match up nested pairs of strings. Array $a would be the offsets for opening tags, while array $b would be the offsets of closing tags.
bobbinsbro : The arrays will/should always be in ascending order... and if it wasn't, I can always use sort() before looping.
sasa: Yes, they should both be in ascending order at all times.
corbin: It's part of the algorithm. In order to find the correct matching pairs, it takes the least amount of work to start from the opening end ( deepest element ) and work your way up/out.
Just to clear things up, here's what I'm doing, in a wider scope. This is a crude example... the actual code I'm using is nested in a class with a ton of erroneous garbage so I shortened it up
[edit] oops, gotta clean a few things up before i can provide an example [/edit]
Thanks for your replies thus far
-
Shameless BUMP
-
Well, if you want to follow PHP's function naming spec.
'/[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]++\([^)]++\)/i'
This is assuming you won't use literal strings with closing brackets in your function... for example
bleh('Stuff with a ) closing bracket')
If you want something like that, the expression becomes quite a bit more complex
-
First I'll try to explain the problem.
I have 2 arrays of identical size, similar to the example below
$a = array( 2, 29, 54, 77 ); $b = array( 66, 72, 102, 107 );
I want to go through each value of $a in reverse, and find the lowest value of $b that is greater than the current value of $a. To add to this mess, I don't want to reuse any values of $b when pairing them with values from $a
Here's what I've got so far
<pre><?php $a = array( 2, 29, 54, 77 ); $b = array( 66, 72, 102, 107 ); // Placeholder for found pairs $pairs = array(); // Loop through $a backwards foreach( array_reverse($a) as $aVal ) { /***** THIS IS THE CHUNK I THINK CAN BE IMPROVED ON *****/ // Loop through $b until we find a value less than the current $a foreach( $b as $bKey => $bVal ) // Check to see if the current value of b is less than the current value of a if( $aVal < $bVal ) { // If so, add it to the pairs $pairs[] = array( $aVal, $bVal ); // Unset used value of b - prevents duplication and should speed things up unset( $b[$bKey] ); // Break out of the loop break; } /***** END OF CHUNK *****/ } print_r( $pairs ); ?></pre>
The output should look like this
Array ( [0] => Array ( [0] => 77 [1] => 102 ) [1] => Array ( [0] => 54 [1] => 66 ) [2] => Array ( [0] => 29 [1] => 72 ) [3] => Array ( [0] => 2 [1] => 107 ) )
Any help is greatly appreciated. I'm hoping there's some cool array trick I just don't know about.
Thanks for lookin'
-
I believe underscore is already matched in the \w shorthand so you could make it even shorter
-
This regex should perform the same thing in less steps than the above example
preg_match_all('%<a target[^>]*+>([^<]++)</a>%', $subject, $result, PREG_PATTERN_ORDER); print_r($result[1]);
-
Ah, should've tested it.
-
Don't trust mimetype - It's defined by the client. Instead, check the extension and if you have the extension, check the _real_ mimetype using http://php.net/fileinfo
-
I would do it like this
<pre><?php $person = array("frank_jones","jim_smith","sandy_mitchell"); $folder = array("007","002","010"); $name = array("Frank","Jim","Sandy"); for( $i = 0, $c = count($person); $i < $c; $i++ ) { echo "Person: {$person[$i]} \n"; echo "Folder: {$folder[$i]} \n"; echo "Name: {$name[$i]} \n"; echo "\n"; } ?></pre>
-
I'd do something like this:
<?php $code = <<<CODE some content goes here <?php morePHPcode(); while ( !($succeed = try()) ); echo 'foo'.\$bar; ?> here's some <b>more</b> content, ect. ect. CODE; echo hiliteCode( $code ); function hiliteCode( $input ) { $regex = '/<\?.*?\?>/s'; return preg_replace_callback( $regex, create_function( '$m', 'return "<pre>".highlight_string( $m[0], TRUE )."</pre>";' ), $input ); } ?>
-
I think i see what you mean... try this guy
<pre><?php $subject = 'The cat sat on the [[straw|mat]]. The cat hoped he would jump through the [[windows]] and catch the [[feathered variety|bird on the branch]].'; $array = getValues( $subject ); print_r( $array ); function getValues( $input ) { $regex = '/\[\[([^|\]]++)(?:\|([^\]]++)){0,1}/'; if( preg_match_all($regex, $input, $matches, PREG_SET_ORDER) < 1 ) return array(); $return = array(); foreach( $matches as $m ) { if( isset($m[2]) === FALSE ) $return[] = $m[1]; else $return[] = $m[2]; } return $return; } ?></pre>
-
Type casting or ctype_digit() would be better than is_numeric()
-
This would be pretty tricky to do. Why on earth do you need the SFN?
-
This may help
Note: Parent constructors are not called implicitly if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required. -
print_r( $_REQUEST['cmd'] );
Images return an array of the x,y coordinates that were clicked.
While loop help please?
in PHP Coding Help
Posted
Jibberish has it. You must reset the internal pointer after
$row = mysql_fetch_array($result);
Remove it or try mysql_data_seek()