Script keeps outputing different hashes for same password!
Posted: Mon Aug 25, 2014 2:34 pm
Greetings PHP technorati. I hope all is well with everyone. I seek guidance on a code that keeps outputing different hashes for the same password input. Can someone show me how to edit code so that it will produce the same hash for the same password input? thanks in advance.
Sincerely,
Batoe
Code: Select all
function myObscurepass($userpassword, $saltHash=NULL, $mode='sha1'){
// hash the text //
$textHash = hash($mode, $userpassword);
// set where salt will appear in hash //
$saltStart = strlen($userpassword);
// if no salt given create random one //
if($saltHash == NULL) {
$saltHash = hash($mode, uniqid(rand(), true));
}
// add salt into text hash at pass length position and hash it //
if($saltStart > 0 && $saltStart < strlen($saltHash)) {
$textHashStart = substr($textHash,0,$saltStart);
$textHashEnd = substr($textHash,$saltStart,strlen($saltHash));
$outHash = hash($mode, $textHashEnd.$saltHash.$textHashStart);
} elseif($saltStart > (strlen($saltHash)-1)) {
$outHash = hash($mode, $textHash.$saltHash);
} else {
$outHash = hash($mode, $saltHash.$textHash);
}
// put salt at front of hash //
$output = $saltHash.$outHash;
return $output;
}
Batoe