selberbauer
Captain
- Registriert
- Juni 2009
- Beiträge
- 3.604
Hallo,
ich habe eine Klasse, welche für mich die Session Verwaltung übernimmt.
Beim aufrufen der Authentifications-Methode muss irgendwas schief laufen, ich weiß aber nicht was.
ich habe eine Klasse, welche für mich die Session Verwaltung übernimmt.
Beim aufrufen der Authentifications-Methode muss irgendwas schief laufen, ich weiß aber nicht was.
PHP:
<?php
class auth {
private $user;
private $pass;
private $hash;
private $key_1;
private $key_2;
private $link_1 = 'secret.php';
private $link_2 = 'index.php';
public function __construct($_POST) {
$this->key();
if($this->valid($_POST['user'], $_POST['pass'])) {
$this->auth();
}
}
private function key() {
$rand = hash('SHA512', rand());
$str = str_split($random, 32);
$this->key_1 = $str[0].date('m.d.Y H:i:s').$str[1];
$this->key_2 = $str[2].$_SERVER['HTTP_USER_AGENT'].$str[3];
}
private function valid($username, $password) {
$_SESSION['state'] = FALSE;
if(isset($username, $password)) {
$this->user = $username;
$this->user = $password;
$this->hash = hash('SHA512', $this->pass);
return TRUE;
} else {
return FALSE;
}
}
public function auth() {
$db = new mysqli(HOST, USER, PASS, DATA);
if($stmt = $db->prepare('SELECT user, hash, status FROM user WHERE user = ? AND hash = ? AND status = 1')) {
$stmt->bind_param('ss', $this->user, $this->hash);
$stmt->execute();
$stmt->store_result();
$state = $stmt->num_rows();
$stmt->close();
}
echo $state;
if($state == 1) {
$_SESSION['state'] = TRUE;
$_SESSION['time'] = date('m.d.Y H:i:s');
$_SESSION['one'] = $this->key_1;
$_SESSION['two'] = $this->key_2;
header('Location: '.$this->link_1);
exit();
} else {
return FALSE;
}
}
public function ini() {
session_start();
if( (!$_SESSION['state']) OR ($_SESSION['one'] != $this->key_1) OR ($_SESSION['two'] != $this->key_2) ) {
header('Location: '.$link_1);
exit();
}
}
public function logout() {
session_start();
session_destroy();
session_unset();
}
}
?>