It shoots always to
if($this->parool_exists != $this->passmd5)
$this->errors[] = '<font color="red">Password is not correct</font>';
even if it is!
Really need to know what the problem is here!
<?php
class Seaded
{
private $parool;
private $uparool;
private $uparool2;
private $passmd5;
private $errors;
private $stoken;
public function __construct()
{
$this->errors = array();
$this->parool = $this->filter($_POST['parool']);
$this->uparool = $this->filter($_POST['uparool']);
$this->uparool2 = $this->filter($_POST['uparool2']);
$this->stoken = $_POST['stoken'];
$this->passmd5 = md5($this->parool);
}
public function process()
{
if($this->valid_stoken() && $this->valid_data())
$this->seaded();
return count($this->errors)? 0 : 1;
}
public function filter($var)
{
return preg_replace('/[^a-zA-Z0-9@.]/','',$var);
}
public function seaded()
{
mysql_query("UPDATE andmed(parool) VALUES ('{$this->uparool}')");
if(mysql_affected_rows()< 1)
$this->errors[] = '<font color="red">Andmebaasi viga</font>';
}
public function parool_exists()
{
mysql_query("SELECT parool FROM andmed WHERE kasutajanimi='".$_SESSION['kasutajanimi']."'");
}
public function show_errors()
{
echo "";
foreach($this->errors as $key=>$value)
echo $value."<br>";
}
public function valid_data()
{
if($this->parool_exists != $this->passmd5)
$this->errors[] = '<font color="red">Password is not correct</font>';
if(empty($this->parool))
$this->errors[] = '<font color="red">Sisestage kõik lahtrid</font>';
if(empty($this->uparool))
$this->errors[] = '<font color="red">Sisestage kõik lahtrid</font>';
if(empty($this->uparool2))
$this->errors[] = '<font color="red">Sisestage kõik lahtrid</font>';
if($this->uparool != $this->uparool2)
$this->errors[] = '<font color="red">Paroolid ei ühti</font>';
return count($this->errors)? 0 : 1;
}
public function valid_stoken()
{
if(!isset($_SESSION['stoken']) || $this->stoken != $_SESSION['stoken'])
$this->errors[] = '<font color="red">Kontrollige andmeid</font>';
return count($this->errors)? 0 : 1;
}
}
?>