From c5a9c71a1fbade72f35b5d39c5f71380436e96ce Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Fri, 11 Jan 2019 14:13:50 +0100 Subject: password hash option retro compatible --- app/class/user.php | 84 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 25 deletions(-) (limited to 'app/class/user.php') diff --git a/app/class/user.php b/app/class/user.php index 8fb152f..2627d3d 100644 --- a/app/class/user.php +++ b/app/class/user.php @@ -6,33 +6,35 @@ class User protected $level = 0; protected $signature = ''; protected $password; + protected $passwordhashed = false; - public function __construct($datas = []) { - if(!empty($datas)) { + public function __construct($datas = []) + { + if (!empty($datas)) { $this->hydrate($datas); } } public function hydrate($datas = []) - { - foreach ($datas as $key => $value) { - $method = 'set' . $key; + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; - if (method_exists($this, $method)) { - $this->$method($value); - } - } + if (method_exists($this, $method)) { + $this->$method($value); + } + } } - public function dry() - { - $array = []; - foreach (get_class_vars(__class__) as $var => $value) { - $array[$var] = $this->$var(); - } - return $array; + public function dry() + { + $array = []; + foreach (get_class_vars(__class__) as $var => $value) { + $array[$var] = $this->$var(); + } + return $array; } - + public function id() { return $this->id; @@ -45,50 +47,82 @@ class User public function password($type = 'string') { - if($type === 'int') { + if ($type === 'int') { return strlen($this->password); } elseif ($type = 'string') { return $this->password; } } - + public function signature() { return $this->signature; } + public function passwordhashed() + { + return $this->passwordhashed; + } + public function setid($id) { $id = idclean($id); if (strlen($id) < Model::MAX_ID_LENGTH and is_string($id)) { - $this->id = $id; - } + $this->id = $id; + } } - + public function setlevel($level) { $level = intval($level); - if($level >= 0 && $level <= 10) { + if ($level >= 0 && $level <= 10) { $this->level = $level; } } public function setpassword(string $password) { - if(strlen($password) >= 4 && strlen($password) <= 32) { + if (is_string($password)) { $this->password = $password; } + } public function setsignature(string $signature) { - if(strlen($signature) <= 128) { + if (strlen($signature) <= 128) { $this->signature = $signature; } } + public function setpasswordhashed($passwordhashed) + { + $this->passwordhashed = boolval($passwordhashed); + + } + + + + + + public function hashpassword() + { + $this->password = password_hash($this->password, PASSWORD_DEFAULT); + $this->passwordhashed = true; + } + + public function validpassword() + { + if(is_string($this->password)) { + if(strlen($this->password) >= Model::PASSWORD_MIN_LENGTH && strlen($this->password) <= Model::PASSWORD_MAX_LENGTH) { + return true; + } + } + return false; + } + public function isvisitor() -- cgit v1.2.3 From b361e2e5d5bdb6cc6256d50f8292c910fc4d3de0 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Fri, 11 Jan 2019 18:09:55 +0100 Subject: user hash fix update --- app/class/user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/class/user.php') diff --git a/app/class/user.php b/app/class/user.php index 2627d3d..9bfc071 100644 --- a/app/class/user.php +++ b/app/class/user.php @@ -82,7 +82,7 @@ class User public function setpassword(string $password) { - if (is_string($password)) { + if (is_string($password) && !empty($password)) { $this->password = $password; } -- cgit v1.2.3