aboutsummaryrefslogtreecommitdiff
path: root/Html/classes/class.user.php
diff options
context:
space:
mode:
authorcitizenz7 <citizenz7@protonmail.com>2017-04-20 18:50:55 +0200
committercitizenz7 <citizenz7@protonmail.com>2017-04-20 18:50:55 +0200
commit5fd9fa480f302902328b81f912dd67ce378284f8 (patch)
tree66234843ae2857fda12442e4f7577c527d48977c /Html/classes/class.user.php
parentebe731862c7c741171138b1083906f391fc35aff (diff)
downloadfreetorrent-5fd9fa480f302902328b81f912dd67ce378284f8.tar.xz
freetorrent-5fd9fa480f302902328b81f912dd67ce378284f8.zip
V.1.4.6
Diffstat (limited to 'Html/classes/class.user.php')
-rw-r--r--Html/classes/class.user.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/Html/classes/class.user.php b/Html/classes/class.user.php
new file mode 100644
index 0000000..b0f5e57
--- /dev/null
+++ b/Html/classes/class.user.php
@@ -0,0 +1,68 @@
+<?php
+
+include('class.password.php');
+
+class User extends Password{
+
+ private $db;
+
+ function __construct($db){
+ parent::__construct();
+
+ $this->_db = $db;
+ }
+
+ public function is_logged_in(){
+ if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true){
+ return true;
+ }
+ }
+
+ private function get_user_hash($username){
+
+ try {
+
+ $stmt = $this->_db->prepare('SELECT password FROM blog_members WHERE username = :username');
+ $stmt->execute(array('username' => $username));
+
+ $row = $stmt->fetch();
+ return $row['password'];
+
+ } catch(PDOException $e) {
+ echo '<p class="error">'.$e->getMessage().'</p>';
+ }
+ }
+
+
+ public function login($username,$password){
+
+ $hashed = $this->get_user_hash($username);
+
+ try {
+
+ $stmt = $this->_db->prepare('SELECT memberID,password,active FROM blog_members WHERE username = :username');
+ $stmt->execute(array('username' => $username));
+ $row = $stmt->fetch();
+
+ if($this->password_verify($password,$hashed) == 1 && $row['active'] == 'yes') {
+ $_SESSION['time'] = time();
+ $_SESSION['loggedin'] = true;
+ $_SESSION['username'] = $username;
+ $_SESSION['userid'] = $row['memberID'];
+
+ return true;
+ }
+
+ } catch(PDOException $e) {
+ echo '<p class="error">'.$e->getMessage().'</p>';
+ }
+ }
+
+
+ public function logout(){
+ session_destroy();
+ }
+
+}
+
+?>