public function testPassword()
 {
     $passwd = password_hash('WowSoSecretPassword', PASSWORD_DEFAULT);
     $this->assertEmpty($this->user->getPassword());
     $this->user->setPassword($passwd);
     $this->assertEquals($passwd, $this->user->getPassword());
 }
 public function login($POST)
 {
     $db = new DB();
     $user = new User();
     $user->setEmail($POST["email"]);
     $user->setPassword($POST["password"]);
     if ($user->getEmail() == "") {
         $response["status"] = 1;
         $response["msg"] = "กรุณากรอก Email";
     } else {
         if ($user->getPassword() == "") {
             $response["status"] = 2;
             $response["msg"] = "กรุณากรอก Password";
         } else {
             $array = array("email" => array("type" => $user->getDataType("email"), "value" => $user->getEmail()), array("type" => $user->getDataType("password"), "value" => $user->getPassword()));
             $sql = "SELECT * FROM users WHERE email = ? AND password = ?";
             $data = $db->query($sql, $array);
             if (count($data) > 0) {
                 $response["status"] = 0;
                 $response["msg"] = "Success";
             } else {
                 $response["status"] = -1;
                 $response["msg"] = "ไม่พบ Email/Password นี้ในระบบ";
             }
         }
     }
     echo json_encode($response);
 }
Example #3
0
 public function verify(User $user)
 {
     if (!isset($this->password) && isset($this->hash)) {
         if ($user->getPassword() == $this->hash) {
             return true;
         }
         return false;
     }
     return password_verify($this->password, $user->getPassword());
 }
function verifyCredentials($username, $password)
{
    $loginDB = new LoginDB();
    $user = null;
    $users = array();
    $res = $loginDB->getAccount($username);
    while ($users = $res->fetch_object()) {
        if ($users->Username == null) {
            exit;
        }
        $dbUsername = $users->Username;
        $dbPassword = $users->Password;
        $dbRoleId = $users->Role_ID;
        $dbCostumerId = $users->Costumer_ID;
        $user = new User($dbUsername);
        $user->setPassword($dbPassword);
        $user->setRoleId($dbRoleId);
        $user->setCostumerId($dbCostumerId);
    }
    if ($user != null) {
        if (strtolower($user->getUsername()) == strtolower($username) && $user->getPassword() == $password) {
            $_SESSION["user"] = $user;
            header("Location: ../index.php");
        }
    }
}
Example #5
0
 public function present(User $user)
 {
     $name = $this->presentName($user->getName());
     $email = $this->presentEmail($user->getEmail());
     $password = $this->presentPassword($user->getPassword());
     return join('', ['Your name is: ', $name, PHP_EOL, 'Your email is: ', $email, PHP_EOL, 'Your password is: ', $password, PHP_EOL]);
 }
 private function updateUser($userId)
 {
     $users = UsersDB::getUsersBy('user_id', $userId);
     if (empty($users)) {
         HomeView::show();
         header('Location: /' . $_SESSION['base']);
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
             $_SESSION['user'] = $users[0];
             UserView::showUpdate();
         } else {
             $params = $users[0]->getParameters();
             $params['username'] = array_key_exists('username', $_POST) ? $_POST['username'] : "";
             $params['password'] = array_key_exists('password', $_POST) ? $_POST['password'] : "";
             $updatedUser = new User($params);
             $updatedUser->setUserId($users[0]->getUserId());
             $plaintextPassword = $updatedUser->getPassword();
             $hashedPassword = password_hash($plaintextPassword, PASSWORD_DEFAULT);
             $updatedUser->setPassword($hashedPassword);
             $returnedUser = UsersDB::updateUser($updatedUser);
             if ($returnedUser->getErrorCount() == 0) {
                 // TODO: Log out the current user before diplaying the HomeView; LogoutController::LogoutCurrentUser()
                 HomeView::show();
                 header('Location: /' . $_SESSION['base']);
             } else {
                 $_SESSION['user'] = $updatedUser;
                 UserView::showUpdate();
             }
         }
     }
 }
Example #7
0
 public function equals(User $user)
 {
     if (strcmp($this->username, $user->getUsername()) == 0 && strcmp($this->password, $user->getPassword()) == 0 && ($this->id == $user->getId()) == TRUE) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
 public function createUser(User $user)
 {
     $user->setId(null);
     $sql = '
         INSERT INTO users_tb(id,email, user_password)
             VALUES (:id,:email,:user_password)';
     $params = array(':id' => $user->getId(), ':email' => $user->getEmail(), ':user_password' => $user->getPassword());
     return $this->execute($sql, $user, $params);
 }
Example #9
0
 public function login(\User $user)
 {
     $query = "SELECT *from user where User_Name='" . $user->getUsername() . "' and User_Password='" . $user->getPassword() . "'";
     $userExit = $this->conn->query($query);
     if ($userExit) {
         return true;
     }
     return false;
 }
Example #10
0
 public function checkPasswordUser(User $user)
 {
     $STH = $this->DBH->prepare("SELECT * FROM Users WHERE login=:login and password=:password ");
     $STH->bindValue(":login", $user->getLogin());
     $STH->bindValue(":password", $user->getPassword());
     $STH->execute();
     $STH->setFetchMode(PDO::FETCH_CLASS, 'user');
     return $STH->fetch();
 }
Example #11
0
 public static function doUpdate(User $vo)
 {
     $user = R::dispense('user');
     $user->id = $vo->getId();
     $user->username = $vo->getUserName();
     $user->status = $vo->getStatus();
     $user->password = $vo->getPassword();
     return $id = R::store($user);
 }
Example #12
0
 public function testSetGetPassword()
 {
     // Arrange
     $user = new User();
     $user->setPassword('top secret');
     $expectedResult = 'top secret';
     // Act
     $result = $user->getPassword();
     // Assert
     $this->assertEquals($result, $expectedResult);
 }
Example #13
0
 public function add(User $toBeAdded)
 {
     $stmt = $this->database->prepare("INSERT INTO  `a9523293_mirza`.`users` (\n\t\t\t`username` , `password`)\n\t\t\t\tVALUES (?, ?)");
     if ($stmt === FALSE) {
         throw new Exception($this->database->error);
     }
     $usern = $toBeAdded->getUsername();
     $pass = $toBeAdded->getPassword();
     $stmt->bind_param('ss', $usern, $pass);
     $stmt->execute();
 }
 /**
  * @test
  */
 public function testUserProperties()
 {
     $uid = '123';
     $nick = 'test';
     $email = 'test@test.test';
     $user = new User($uid, $nick, $email);
     $this->assertEquals($nick, $user->getUsername());
     $this->assertEquals(null, $user->getSalt());
     $this->assertEquals(array('ROLE_USER'), $user->getRoles());
     $this->assertEquals('', $user->getPassword());
 }
 public static function add(User $user)
 {
     $insertUser = Db::pdoConnect()->prepare("INSERT INTO user SET full_name=:fullname, user_password=:user_password, user_email=:user_email");
     $insertUser->bindValue(':fullname', $user->getFullName(), PDO::PARAM_STR);
     $insertUser->bindValue(':user_password', $user->getPassword(), PDO::PARAM_STR);
     $insertUser->bindValue(':user_email', $user->getUserEmail(), PDO::PARAM_STR);
     $insertUser->execute();
     $lastId = Db::pdoConnect()->lastInsertId();
     $user->setUserId($lastId);
     return $user;
 }
Example #16
0
 public function add(User $toBeAdded)
 {
     $stmt = $this->database->prepare("INSERT INTO `a7600781_reg`.`users` (\n\t\t\t`username` , `password` )\n\t\t\t\tVALUES (?, ?)");
     if ($stmt === FALSE) {
         throw new Exception($this->database->error);
     }
     $userName = $toBeAdded->getName();
     $userPassword = $toBeAdded->getPassword();
     $stmt->bind_param('ss', $userName, $userPassword);
     $stmt->execute();
 }
Example #17
0
 public function testAccessors()
 {
     $user = new User();
     $user->setId('12345');
     $user->setEmail('example@devba.se');
     $user->setPassword('password1');
     $user->setConfirm('password2');
     $this->assertEquals('12345', $user->getId());
     $this->assertEquals('example@devba.se', $user->getEmail());
     $this->assertEquals('password1', $user->getPassword());
     $this->assertEquals('password2', $user->getConfirm());
 }
Example #18
0
 /**
  * Add user to the database.
  * 
  * @param \model\User $user The user to be added to the database
  */
 public function add(User $user)
 {
     $sqli = $this->database->connect();
     $stmt = $sqli->prepare("INSERT INTO `users`(`username`, `password`) VALUES (?, ?)");
     if ($stmt === FALSE) {
         throw new Exception($sqli->error);
     }
     $username = $user->getUsername();
     $password = $user->getPassword();
     $stmt->bind_param('ss', $username, $password);
     $stmt->execute();
 }
Example #19
0
 public function create(User $user)
 {
     try {
         $db = $this->connection();
         $sql = "INSERT INTO {$this->table}(" . self::$userID . ", " . self::$name . ", " . self::$password . " ) VALUES (?, ?, ?)";
         $params = array("", $user->getUserName(), $user->getPassword());
         $query = $db->prepare($sql);
         $query->execute($params);
     } catch (\PDOException $e) {
         die('An unknown error have occured.');
     }
 }
 public function emailPasswordCheck(User $user)
 {
     $result = array();
     $email = $user->getEmail();
     $password = $user->getPassword();
     $sql = 'SELECT id,email,user_password FROM users_tb WHERE ' . 'email = "' . $email . ' "  AND ' . 'user_password = "' . $password . '" ;';
     foreach ($this->query($sql) as $row) {
         $userObj = new User();
         UserMapper::map($userObj, $row);
         $result[$userObj->getId()] = $userObj;
     }
     return $result;
 }
Example #21
0
 public function auth(User $loginUser)
 {
     $imap = true;
     if (!$imap) {
         return FALSE;
     } else {
         if ($user = $this->db->fetchAssoc("SELECT p.id, p.heslo, p.meno, p.role, t.rocnik, t.kod, p.trieda_id FROM pouzivatelia AS p LEFT JOIN triedy AS t ON p.trieda_id = t.id WHERE p.login = ?", array($loginUser->getLogin()))) {
             return $user['heslo'] === md5($loginUser->getPassword()) ? $user : FALSE;
         } else {
             return FALSE;
         }
     }
 }
Example #22
0
 /**
  * Add user to the database.
  * User for registration.
  *
  * @param \model\User $user The user to be added to the database
  */
 public function add(User $user)
 {
     $sqli = $this->database->connect();
     $stmt = $sqli->prepare("INSERT INTO " . $this->table . "(" . $this->usernameCol . ", " . $this->passwordCol . ", " . $this->profileinfoCol . ") VALUES (?, ?, ?)");
     if ($stmt === FALSE) {
         throw new Exception($sqli->error);
     }
     $username = $user->getUsername();
     $password = $user->getPassword();
     $profileinfo = $user->getProfile();
     $stmt->bind_param('sss', $username, $password, $profileinfo);
     $stmt->execute();
 }
 public function create(User $u)
 {
     $q = $this->_db->prepare('INSERT INTO users (email,firstName,lastName,phone,password) VALUES(:em,:fn,:ln,:ph,:pass) ');
     $q->bindValue(':fn', $u->getFirstName(), PDO::PARAM_STR);
     $q->bindValue(':ln', $u->getLastName(), PDO::PARAM_STR);
     $q->bindValue(':em', $u->getEmail(), PDO::PARAM_STR);
     $q->bindValue(':ph', $u->getPhone(), PDO::PARAM_STR);
     $q->bindValue(':pass', $u->getPassword(), PDO::PARAM_STR);
     try {
         $q->execute();
     } catch (Exception $e) {
         echo "Error at user creation";
     }
 }
Example #24
0
 /**
  * This function update and insert user record
  * @param \Music\Model\User $user
  * @throws \Exception
  */
 public function saveUser(User $user, $user_id)
 {
     $data = array('username' => $user->getUsername(), 'password' => md5($user->getPassword()), 'role' => $user->getRole(), 'fullname' => $user->getFullName());
     $user_id = (int) $user->getUserId();
     if (!$user_id) {
         $this->tableGateway->insert($data);
     } else {
         if ($user_id) {
             $this->tableGateway->update($data, array('user_id' => $user_id));
         } else {
             throw new \Exception('Form id does not exist');
         }
     }
 }
Example #25
0
 public function autenticate(User &$user)
 {
     $table = strtolower($user->get_called_class());
     $array = array('username' => $user->getUsername()->get(), 'password' => $user->getPassword()->get(), 'hashtype' => $user->getHashtype()->get());
     $sql = $this->sql(array('query' => self::$FILTER, 'table' => $table, 'data' => $array));
     $db = DataBase::getInstance();
     $resp = $db->execute($sql);
     if ($resp && count($resp)) {
         $user->setVerified(true);
         $user->setArray($resp[0]);
         return true;
     }
     return false;
 }
Example #26
0
 public function update(User $user)
 {
     $id = $user->getId();
     $login = $this->db->quote($user->getLogin());
     $password = $this->db->quote($user->getPassword());
     $email = $this->db->quote($user->getEmail());
     $avatar = $this->db->quote($user->getAvatar());
     $query = "UPDATE\t user \n\t\t\t\t\t\tSET \tlogin\t\t='" . $login . "', \n\t\t\t\t\t\t\t\tpassword\t='" . $password . "',\n\t\t\t\t\t\t\t\temail\t\t='" . $email . "', \n\t\t\t\t\t\t\t\tavatar\t\t='" . $avatar . "' \n\t\t\t\t\t\t\t\tWHERE id\t='" . $id . "'";
     $res = $this->db->exec($query);
     if ($res) {
         return $this->findById($id);
     } else {
         throw new Exception("Internal Server Error");
     }
 }
Example #27
0
 public function saveUserToDatabase(User $user)
 {
     //if database connection is null, re-establish a new connection
     if ($this->db == null) {
         $this->connect();
     }
     $stmt = $this->db->prepare($this->connection->insertUserSQL());
     $name = $user->getUsername();
     $pass = password_hash($user->getPassword(), PASSWORD_BCRYPT);
     $stmt->bind_param('ss', $name, $pass);
     $stmt->execute();
     //Close db connection and set db to null
     $this->db->close();
     $this->db = null;
 }
Example #28
0
 public function addUserToDatabase(User $user)
 {
     $username = $user->getUsername();
     $password = $user->getPassword();
     $connection = $this->createConnection();
     $mysql_database = Settings::$mysql_database;
     $sqlQuery = "INSERT INTO {$mysql_database}.`member` (`Username`, `Password`) VALUES ('{$username}', '{$password}')";
     $result = $connection->query($sqlQuery);
     $this->closeConnection();
     //if the query failed result will be false
     if (!$result) {
         return false;
     }
     return true;
 }
Example #29
0
 /**
  * Load the user object into the user property
  *
  * @return User
  */
 public static function loadUser($user = null)
 {
     try {
         $classname = self::$_configuration['core']['user_classname'];
         $request = self::getRequest();
         self::$_user = $user === null ? $classname::loginCheck($request->getParameter('csp_username', $request->getCookie('csp_username')), $request->getParameter('csp_password', $request->getCookie('csp_password')), !$request->hasCookie('csp_password')) : $user;
         if (self::$_user->isAuthenticated()) {
             self::getResponse()->setCookie('csp_username', self::$_user->getUsername());
             self::getResponse()->setCookie('csp_password', self::$_user->getPassword());
             Event::createNew('core', 'post_loaduser', self::$_user)->trigger();
         }
     } catch (Exception $e) {
         throw $e;
     }
     return self::$_user;
 }
Example #30
0
 /**
  * @param string $password
  * @return bool
  */
 private function setPassword($password)
 {
     $passwordFactory = $this->user->getPasswordFactory();
     $oldDefaultType = $passwordFactory->getDefaultType();
     // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
     $passwordFactory->setDefaultType('A');
     $newPassword = $passwordFactory->newFromPlaintext($password, $this->user->getPassword());
     $change = false;
     if (!$this->user->getPassword()->equals($newPassword)) {
         // Password changed
         $this->user->setPassword($password);
         $change = true;
     }
     $passwordFactory->setDefaultType($oldDefaultType);
     return $change;
 }