So I've been writing code for a project of mine where I have to create a sign up and login system for a website, and I'm pretty stuck right now. I call the following "UserLogin.php" file:
class UserLogin
{
private $username;
private $firstName;
private $lastName;
private $userid;
private $emailaddr;
private $error;
private $db;
private $hash;
private $salt;
private $password
public function __construct($user, $pass)
{
$this['username'] = $user;
$this['password'] = $pass;
}
function getError()
{
return $this->error;
}
public function userLogin($username, $password)
{
if (checkUser($username)) {
if (checkPass($password)) {
$_SESSION['memberName'] = $this['username'];
$_SESSION['fName'] = $this['firstName'];
$_SESSION['lName'] = $this['lastName'];
return true;
}
} else {
$error = "Invalid username/password";
}
}
public function checkUser($username)
{
$mysqli = new mysqli('hostip', 'username', 'password', 'dbname', 3306);
$stmt = prepare($mysqli);
bind_param($stmt, "s", $username);
execute($stmt);
bind_result($stmt, $this['user_id'], $this['username'], $this['salt'], $this['hash']);
if (isset(fetch($stmt))) {
return false;
}
return true;
}
public function checkPass($password)
{
return hash_equals($this['hash'], crypt($password, $this['hash']));
//return (hash_hmac("sha256", $password, $this['salt']) === $this['hash']);
}
from another file, after the user has entered their username and password and then hit enter:
include 'UserLogin.php';
$username = $_GET["username"];
$password = $_GET["pwd"];
$usersession = new UserLogin($username, $password);
echo "created";
$var = $usersession->userLogin($username, $password);
if ($var){
echo "Verified";
}
Thus far, I have not been able to find any errors but my website does not finish loading after the login button is hit. Any help would be greatly appreciated. Also note I censored my actual database info in the mysqli variable.
You're missing your semicolon after private $password
You're missing semicolons (after $password
), isset()
can't to be called on a function and you can't use the class as an array $this['username']
, you have to call it like $this->username
.
Also your userLogin()
method returns true if all ok but does nothing if user/pass are wrong.
The only real advice is to look at the error log and solve them one by one.