Note that there are some explanatory texts on larger screens.

plurals
  1. POError with PHPass on authentification
    text
    copied!<p>I'm using PHPass for password encryption and for authenticating login.</p> <p>When I try login, it gives errors:_</p> <p>Warning: mysqli::prepare() [mysqli.prepare]: invalid object or resource C:\mysqli rootfile-blahblahblah\includes\user.php on line 41</p> <p>Fatal error: Call to a member function bind_param() on a non-object in C:\rootfile-blahblahblah\includes\user.php on line 43</p> <p>I followed the manual for authentication but it's ont working for some reason.</p> <p>Heres the code of the authentication function</p> <pre><code> public static function authenticate($username, $password) { $pwdhasher = new PasswordHash(8, FALSE); $hashed_pwd = $pwdhasher-&gt;HashPassword($password); $db = new mysqli(); $stmt = $db-&gt;prepare("SELECT hashed_password FROM users WHERE username=? LIMIT 1"); if (!$stmt) die($db-&gt;error); $stmt-&gt;bind_param('s', $username); $stmt-&gt;execute(); $stmt-&gt;bind_result($hashed_pwd); if ($pwdhasher-&gt;CheckPassword($password, $hashed_pwd)) { return true; } else { return false; } unset($pwdhasher); } </code></pre> <p>And for the login.php page where it runs the function:_</p> <pre><code>$username = $database-&gt;escape_value(trim($_POST['username'])); $password = $database-&gt;escape_value(trim($_POST['password'])); $user = User::find_by_id(1); $found_user = User::authenticate($username, $password); if ($found_user) { $session-&gt;login($found_user, $user); $message = "You have Logged in."; redirect_to("index.php"); } else { $message = "Incorrect username/password."; } } </code></pre> <p>I've searched alot and tried alot of things, but to no avail. :/</p> <p>Now you see, what I want is it to check the username and hashed password which are in the database and login if they are correct, I know how to checkPassword() and encrypt it with HashPassword, but I can't find how to make it authenticate username and password....</p>
 

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