Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Hashing code not working any longer?
    primarykey
    data
    text
    <p>I used this hash function for a while (got it from the internet). The thing is it used to work immediately but now it is complaining about a paramter. The following is the code:</p> <pre><code>function generateHash($plainText, $salt = null) { if ($salt === null) { $salt = substr(md5(uniqid(rand(), true)), 0, SALT_LENGTH); } else { $salt = substr($salt, 0, SALT_LENGTH); } return $salt . sha1($salt . $plainText); } </code></pre> <p>So I would use this code in the method call:</p> <pre><code>validateUserInput($userid, $pass); </code></pre> <p>and validateUserInput is:</p> <pre><code>function validateUserInput($username, $password) { //$username = mysql_real_escape_string($username); //$password = mysql_real_escape_string($password); if(!$username || !$password) { //$errors['credentials'] = 'Missing Credentials!'; //$_SESSION['errors_array'] = $errors; //echo $errors['credentials']; header("LOCATION:XXXXXXX.php"); } $local_salt = generateHash($password); //echo $local_salt; $groupid; if($username != null &amp;&amp; $password !=null) { connectToServer(); $result = mysql_query("SELECT * FROM users WHERE hashkey = '{$local_salt}'"); while($row_access = mysql_fetch_array($result)) { $groupid = $row_access['groupid']; } if(!isset($result)) { $errors['not_found_user'] = 'No Users Found with Provided Credentials!'; //$_SESSION['errors_array'] = $errors; $userfound = 0; $_SESSION['user_available'] = $userfound; }elseif(isset($result)){ $_SESSION['user_logged'] = array('username' =&gt; $username, 'password' =&gt; $password, 'salt' =&gt; $local_salt, 'groupid' =&gt; $groupid); $userfound = 1; //echo "stored"; $_SESSION['user_available'] = $userfound; } } } </code></pre> <p>finally the error is:</p> <pre><code>Warning: substr() expects parameter 3 to be long, string given in /home/XXXX.php on line 64 </code></pre> <p>This is pointing to the function <code>generateHash()</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload