am working on a simple login script in PHP
, the script seems to work find on my local machine running on PHP version: 7.1.7
but completely fails to run/return anything on my server with PHP 5.2.0
, here is the code:
public function login($username, $password){
$response['error'] = true;
$response['message'] = 'Incorrect credentials';
$user = array();
$stmt = $this->conn->prepare("SELECT * FROM user_tb WHERE username = ?");
$stmt->bind_param("s", $username);
if ($stmt->execute()) {
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
$salt = $user['salt'];
$encrypted_password = $user['password'];
$hash = $this->checkhashSSHA($salt, $password);
if ($encrypted_password == $hash) {
$user['id'] = $user["id"];
$user['fname'] = $user["fname"];
$user['lname'] = $user["lname"];
$user['phone'] = $user["phone"];
$user['city'] = $user["city"];
$user['country'] = $user["country"];
$response['user'] = $user;
$response['error'] = false;
$response['message'] = 'Welcome back.';
}
}
return $response;
}
public function hashSSHA($password) {
$salt = sha1(rand());
$salt = substr($salt, 0, 20);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
public function checkhashSSHA($salt, $password) {
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
}
What could be the problem? am I using methods not supported in PHP 5.2.0
? If so why isn't it even giving error/warnings? someone help me, am out of ideas.