note 90175 added to function.sha1

From: Date: Wed, 08 Apr 2009 23:01:06 +0000
Subject: note 90175 added to function.sha1
Groups: php.notes 
Request: Send a blank email to php-notes+get-152983@lists.php.net to get a copy of this message
A function I created to create salted hash, dependant on password length. This function creates a salted hash, and will embed the salt into the final hash so it can be retrieved later for validation by means of the length of the password that is inputted. Basically to validate, you need to take the length of the password and the amount of characters created by encryption method to pull the salt out the full hash saved, this will get the salt, you can then use this salt to check any pass against whats saved. It uses the method of embedding the salt into the saved hash, the hash is placed into the salt pass hash at a position that is determined by the password you input meaning the attacker never knows your pass length so doesn't know where the random salt is placed in the password. if this sounds confusing, it is.............. // function to obscure passwords // function createHash($inText, $salt=NULL, $mode='sha1'){ // set where salt will appear in hash // $saltStart = (strlen($inText)/2)+1; // split the password by the number above // $splitPass = str_split($inText, $saltStart); // if no salt given create random one // if($salt == NULL) { $salt = hash($mode, time()); } // add salt into the password and hash it // if(count($splitPass) < 2) { $outHash = hash($mode, $salt.$splitPass[0]); } else { $outHash = hash($mode, implode($salt, $splitPass)); } // place salt inside the password hash at password length position // // find location for hiding salt by password length // if((strlen($inText)) > 18) { $hideHash = 19; } else { $hideHash = strlen($inText)+1; } // split pass and salt hash by pass length // $hashStart = substr($outHash,0,$hideHash); $hashEnd = substr($outHash, $hideHash); // put salt into hash // $saltHash = $hashStart.$salt.$hashEnd; return $saltHash; } // end /////////////////////////// ---- Server IP: 92.48.74.199 Probable Submitter: 82.7.25.183 ---- Manual Page -- http://www.php.net/manual/en/function.sha1.php Edit -- https://master.php.net/note/edit/90175 Del: integrated -- https://master.php.net/note/delete/90175/integrated Del: useless -- https://master.php.net/note/delete/90175/useless Del: bad code -- https://master.php.net/note/delete/90175/bad+code Del: spam -- https://master.php.net/note/delete/90175/spam Del: non-english -- https://master.php.net/note/delete/90175/non-english Del: in docs -- https://master.php.net/note/delete/90175/in+docs Del: other reasons-- https://master.php.net/note/delete/90175 Reject -- https://master.php.net/note/reject/90175 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152983) next »