Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Standish
May 21, 2001

PHP associative arrays are really hash tables underneath, so if you have a lot of valid values or a lot of values to validate it's going to faster to search by key not by value:
php:
<?
$acceptableValues=Array(
   "value1"=>1,
   "value2"=>1,
   "value3"=>1,
   "value4"=>1,
   "value5"=>1,
   ...
);

...
$val=$_REQUEST["something"];
if (isset($acceptableValues[$val]))
  // valid
else
  //invalid
...?>
rather than doing a linear search of the array (or string) every time, like in_array() (or strpos()) do.

But if you only have few values to check and you're only calling it once then use whatever code is clearest.

Adbot
ADBOT LOVES YOU

Standish
May 21, 2001

drcru posted:

As long as you're not storing credit card information in your database or working for a bank, you should be fine with just salting your hashes. Try and have a different salt for every person though.
You are correct that the MD5/SHA1 weaknesses are not (yet) a realistic way to crack hashed passwords, however why wouldn't you use SHA-256 when desigining a new system? It's one line of code to change and the attacks on MD5/SHA1 are only going to get better.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply