How should authentication methods be structured within a PHP User class to ensure security and efficiency?
To ensure security and efficiency, authentication methods within a PHP User class should utilize strong hashing algorithms like bcrypt for storing passwords, implement secure session management, and incorporate proper input validation to prevent SQL injection and other attacks.
class User {
private $username;
private $password;
public function __construct($username, $password) {
$this->username = $username;
$this->password = password_hash($password, PASSWORD_BCRYPT);
}
public function authenticate($inputPassword) {
return password_verify($inputPassword, $this->password);
}
}