Código PHP:
class MySQLdbAdmin extends mysqli{
private $success;
private $stmt;
public function connect($_server = 'localhost', $_serverUser = 'root', $_serverPwd = null, $_serverDB = null){
parent::__construct($_server, $_serverUser, $_serverPwd, $_serverDB) or
die('<h2>There was an error connecting to the database.</h2>');
$this->success = true;
}
private function authenticateUsers($un, $pwd){
$query = "select * from admin where un=? and password=? and password_secure=?";
if($this->stmt = $this->prepare($query)){
$this->stmt->bind_param('ss', $un, md5($pwd), sha1($pwd));
$this->stmt->execute();
if($this->stmt->fetch()){
$this->stmt->close();
return true;
}
return false;
}
}
public function ensureCredentials($un, $pwd, $location = 'admin/admin.php'){
if($this->authenticateUsers($un, $pwd)){
setcookie('admin_credentials', 'granted', 0);
header("location: $location");
}else{
setcookie('admin_credentials', 'revoke', 0);
}
return 0;
}
public function __destruct(){
parent::destruct;
}
}