public function forgotPassword($idclient, $pass) { $hash = new \PasswordHash\PasswordHash(); $sql = 'UPDATE client SET password = :password WHERE idclient = :idclient'; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('idclient', $idclient); $stmt->bindValue('password', $hash->HashPassword($pass)); try { $stmt->execute(); } catch (Exception $e) { throw new FrontendException($e->getMessage()); } return true; }
protected function addOrder($Data) { Db::getInstance()->beginTransaction(); $email = $Data['email']; $password = Core::passwordGenerate(); $hash = new \PasswordHash\PasswordHash(); $sql = 'SELECT idclient FROM client WHERE login = :login'; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('login', $hash->HashLogin($email)); $stmt->execute(); $rs = $stmt->fetch(); if ($rs) { // Update } else { $sql = 'INSERT INTO client (login, password, disable, viewid) VALUES (:login, :password, :disable, :viewid)'; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('login', $hash->HashLogin($email)); $stmt->bindValue('password', $hash->HashPassword($password)); $stmt->bindValue('disable', isset($Data['disable']) ? $Data['disable'] : 0); $stmt->bindValue('viewid', Helper::getViewId()); try { $stmt->execute(); } catch (Exception $e) { throw new FrontendException($e->getMessage()); } $idClient = Db::getInstance()->lastInsertId(); $sql = 'INSERT INTO clientdata SET firstname = AES_ENCRYPT(:firstname, :encryptionKey), surname = AES_ENCRYPT(:surname, :encryptionKey), email = AES_ENCRYPT(:email, :encryptionKey), phone = AES_ENCRYPT(:phone, :encryptionKey), phone2 = AES_ENCRYPT(:phone2, :encryptionKey), description = AES_ENCRYPT(:description, :encryptionKey), clientgroupid = 10, clientid = :clientid '; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('clientid', $idClient); $stmt->bindValue('firstname', $Data['firstname']); $stmt->bindValue('surname', $Data['surname']); $stmt->bindValue('email', $Data['email']); $stmt->bindValue('phone', $Data['phone']); $stmt->bindValue('phone2', !empty($Data['phone2']) ? $Data['phone2'] : ''); $stmt->bindValue('description', !empty($Data['description']) ? $Data['description'] : ''); $stmt->bindValue('encryptionKey', Session::getActiveEncryptionKeyValue()); try { $stmt->execute(); } catch (Exception $e) { throw new FrontendException($e->getMessage()); } $sql = 'INSERT INTO clientaddress SET clientid = :clientid, main = :main, firstname = AES_ENCRYPT(:firstname, :encryptionKey), surname = AES_ENCRYPT(:surname, :encryptionKey), companyname = AES_ENCRYPT(:companyname, :encryptionKey), street = AES_ENCRYPT(:street, :encryptionKey), streetno = AES_ENCRYPT(:streetno, :encryptionKey), placeno = AES_ENCRYPT(:placeno, :encryptionKey), postcode = AES_ENCRYPT(:postcode, :encryptionKey), nip = AES_ENCRYPT(:nip, :encryptionKey), placename = AES_ENCRYPT(:placename, :encryptionKey), countryid = :countryid ON DUPLICATE KEY UPDATE firstname = AES_ENCRYPT(:firstname, :encryptionKey), surname = AES_ENCRYPT(:surname, :encryptionKey), companyname = AES_ENCRYPT(:companyname, :encryptionKey), street = AES_ENCRYPT(:street, :encryptionKey), streetno = AES_ENCRYPT(:streetno, :encryptionKey), placeno = AES_ENCRYPT(:placeno, :encryptionKey), postcode = AES_ENCRYPT(:postcode, :encryptionKey), nip = AES_ENCRYPT(:nip, :encryptionKey), placename = AES_ENCRYPT(:placename, :encryptionKey), countryid = :countryid'; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('encryptionKey', Session::getActiveEncryptionKeyValue()); $stmt->bindValue('clientid', $idClient); $stmt->bindValue('main', 1); $stmt->bindValue('firstname', $Data['firstname']); $stmt->bindValue('surname', $Data['surname']); $stmt->bindValue('companyname', $Data['companyname']); $stmt->bindValue('street', $Data['street']); $stmt->bindValue('streetno', $Data['streetno']); $stmt->bindValue('postcode', $Data['postcode']); $stmt->bindValue('placeno', $Data['placeno']); $stmt->bindValue('nip', $Data['nip']); $stmt->bindValue('placename', $Data['placename']); $stmt->bindValue('countryid', $this->getCountryByName($Data['country'])); try { $stmt->execute(); } catch (Exception $e) { throw new FrontendException($e->getMessage()); } $sql = 'INSERT INTO clientaddress SET clientid = :clientid, main = :main, firstname = AES_ENCRYPT(:firstname, :encryptionKey), surname = AES_ENCRYPT(:surname, :encryptionKey), companyname = AES_ENCRYPT(:companyname, :encryptionKey), street = AES_ENCRYPT(:street, :encryptionKey), streetno = AES_ENCRYPT(:streetno, :encryptionKey), placeno = AES_ENCRYPT(:placeno, :encryptionKey), postcode = AES_ENCRYPT(:postcode, :encryptionKey), nip = AES_ENCRYPT(:nip, :encryptionKey), placename = AES_ENCRYPT(:placename, :encryptionKey), countryid = :countryid ON DUPLICATE KEY UPDATE firstname = AES_ENCRYPT(:firstname, :encryptionKey), surname = AES_ENCRYPT(:surname, :encryptionKey), companyname = AES_ENCRYPT(:companyname, :encryptionKey), street = AES_ENCRYPT(:street, :encryptionKey), streetno = AES_ENCRYPT(:streetno, :encryptionKey), placeno = AES_ENCRYPT(:placeno, :encryptionKey), postcode = AES_ENCRYPT(:postcode, :encryptionKey), nip = AES_ENCRYPT(:nip, :encryptionKey), placename = AES_ENCRYPT(:placename, :encryptionKey), countryid = :countryid'; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('encryptionKey', Session::getActiveEncryptionKeyValue()); $stmt->bindValue('clientid', $idClient); $stmt->bindValue('main', 0); $stmt->bindValue('firstname', $Data['firstname']); $stmt->bindValue('surname', $Data['surname']); $stmt->bindValue('companyname', $Data['companyname']); $stmt->bindValue('street', !empty($Data['street2']) ? $Data['street2'] : $Data['street']); $stmt->bindValue('streetno', !empty($Data['streetno2']) ? $Data['streetno2'] : $Data['streetno']); $stmt->bindValue('postcode', !empty($Data['postcode2']) ? $Data['postcode2'] : $Data['postcode']); $stmt->bindValue('placeno', !empty($Data['placeno2']) ? $Data['placeno2'] : $Data['placeno']); $stmt->bindValue('nip', $Data['nip']); $stmt->bindValue('placename', !empty($Data['placename2']) ? $Data['placename2'] : $Data['placename']); $stmt->bindValue('countryid', $this->getCountryByName(!empty($Data['country2']) ? $Data['country2'] : $Data['country'])); try { $stmt->execute(); } catch (Exception $e) { throw new FrontendException($e->getMessage()); } } Db::getInstance()->commit(); }
protected function addClient($email, $password = '******', $viewid, $active = 0) { if ($email == '') { throw new CoreException(_('ERR_INVALID_EMAIL')); } $hash = new \PasswordHash\PasswordHash(); $sql = 'INSERT INTO client (login, password, disable, viewid) VALUES (:login, :password, :disable, :viewid)'; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('login', $hash->HashLogin($email)); $stmt->bindValue('password', $hash->HashPassword($password)); $stmt->bindValue('disable', $active); if (Helper::getViewId() == 0) { $stmt->bindValue('viewid', $viewid); } else { $stmt->bindValue('viewid', Helper::getViewId()); } try { $stmt->execute(); } catch (Exception $e) { throw new CoreException(_('ERR_CLIENT_ADD'), 4, $e->getMessage()); } return Db::getInstance()->lastInsertId(); }
public function changeUsersPassword($id, $password) { $hash = new \PasswordHash\PasswordHash(); $sql = 'UPDATE user SET password=:password WHERE iduser=:id'; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('password', $hash->HashPassword($password)); $stmt->bindValue('id', $id); try { $stmt->execute(); } catch (Exception $e) { throw new CoreException(_('ERR_PASSWORD_USER_FORGOT'), 13, $e->getMessage()); return false; } return true; }
protected function addUser($email, $password, $active = 1) { if ($email == '') { throw new CoreException(_('TXT_WRONG_EMAIL'), 1001, 'Email is blank -> mysql fix'); } if ($password == NULL) { $password = '******'; } $hash = new \PasswordHash\PasswordHash(); $sql = 'INSERT INTO user SET login = :login, password = :password, active = :active'; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('login', $hash->HashLogin($email)); $stmt->bindValue('password', $hash->HashPassword($password)); $stmt->bindValue('active', $active); try { $stmt->execute(); } catch (Exception $e) { throw new CoreException(_('ERR_USER_ADD'), 20, $e->getMessage()); } return Db::getInstance()->lastInsertId(); }
public function updateClientPass($password) { if (isset($password) && !empty($password)) { $hash = new \PasswordHash\PasswordHash(); $sql = 'UPDATE client SET password = :password WHERE idclient = :idclient'; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('password', $hash->HashPassword($password)); $stmt->bindValue('idclient', Session::getActiveClientid()); try { $stmt->execute(); } catch (Exception $e) { throw new FrontendException(_('ERR_PASSWORD_CLIENT_UPDATE'), 18, $e->getMessage()); } } }