<?php
class Logowanie {
private $user;
private $password;
private $errors;
public function __construct() {
$this->user = $this->filter($_POST['user']);
$this->password = md5($this->filter($_POST['pass'])); }
public function filter($var){
}
public function validate(){
$this->errors[] = 'Podaj poprawna nazwe uzytkownika';
if(empty($this->password)) $this->errors[] = 'Podaj poprawne haslo';
return count($this->errors)? 0
: 1;
}
public function process(){
if($this->validate())
if (login() == $this->password){
$_SESSION['permissions'] = 1;
}
return count($this->errors)? 0
: 1; }
public function show_errors()
{
foreach($this->errors as $key=>$value)
}
public function login(){
try
{
$pdo = new PDO('mysql:host=localhost;dbname=kom', 'root', '');
$pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo -> query("SELECT password FROM users WHERE user = '{$this->user}'");
$stmt -> closeCursor();
}
catch(PDOException $e)
{
echo 'Połączenie nie mogło zostać utworzone: ' . $e->getMessage(); }
return $stmt;
}
?>
<html>
<head>
<title>
logowanie
</title>
</head>
<body>
<?php
if (isset ($_POST['login'])) {
include_once '/logowanie.php';
$a = new Logowanie();
if($a->process())
else
$a->show_errors();
}
?>
<form method="POST" action="
<?php echo $_SERVER['PHP_SELF'];?>">
<table>
<tr><td>User:</td><td><input type="text" name="user"/></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"/></td></tr>
</table>
<input type="submit" name="login" value="Log in"/>
</form>
</body>
</html>
Niestety nie loguje. Czy taka konstrukcja jest prawidłowa:
if (login() == $this->password){
$_SESSION['permissions'] = 1;
}
?
Ten post edytował pawelit 14.09.2011, 12:58:04