getHash() публичный Метод

get the hash
С версии: 2.6.0
public getHash ( )
Пример #1
0
 /**
  * process
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     /* process post */
     $postArray = ['name' => $specialFilter->sanitize($this->_request->getPost('name')), 'user' => $specialFilter->sanitize($this->_request->getPost('user')), 'email' => $emailFilter->sanitize($this->_request->getPost('email')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     /* handle error */
     $messageArray = $this->_validate($postArray);
     if ($messageArray) {
         return $this->_error(['message' => $messageArray]);
     }
     /* handle success */
     $passwordHash = new Hash(Config::getInstance());
     $passwordHash->init(uniqid());
     $createArray = ['name' => $postArray['name'], 'user' => $postArray['user'], 'password' => $passwordHash->getHash(), 'email' => $postArray['email'], 'language' => $this->_registry->get('language'), 'groups' => Db::forTablePrefix('groups')->where('alias', 'members')->findOne()->id, 'status' => Db::getSetting('verification') ? 0 : 1];
     $mailArray = ['name' => $postArray['name'], 'user' => $postArray['user'], 'password' => $passwordHash->getRaw(), 'email' => $postArray['email']];
     /* create */
     if (!$this->_create($createArray)) {
         return $this->_error(['message' => $this->_language->get('something_wrong')]);
     }
     /* mail */
     if (!$this->_mail($mailArray)) {
         return $this->_error(['message' => $this->_language->get('email_failed')]);
     }
     return $this->_success(['message' => Db::getSetting('verification') ? $this->_language->get('registration_verification') : $this->_language->get('registration_sent')]);
 }
Пример #2
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     /* process post */
     $postArray = ['id' => $specialFilter->sanitize($this->_request->getPost('id')), 'password' => $specialFilter->sanitize($this->_request->getPost('password')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     /* query user */
     $user = Db::forTablePrefix('users')->where(['id' => $postArray['id'], 'status' => 1])->findOne();
     /* handle error */
     $messageArray = $this->_validate($postArray, $user);
     if ($messageArray) {
         return $this->_error(['message' => $messageArray]);
     }
     /* handle success */
     $passwordHash = new Hash(Config::getInstance());
     $passwordHash->init(uniqid());
     $resetArray = ['id' => $user->id, 'password' => $passwordHash->getHash()];
     $mailArray = ['name' => $user->name, 'email' => $user->email, 'password' => $passwordHash->getRaw()];
     /* reset */
     if (!$this->_reset($resetArray)) {
         return $this->_error(['message' => $this->_language->get('something_wrong')]);
     }
     /* mail */
     if (!$this->_mail($mailArray)) {
         return $this->_error(['message' => $this->_language->get('email_failed')]);
     }
     return $this->_success();
 }
Пример #3
0
 /**
  * setUpBeforeClass
  *
  * @since 3.0.0
  */
 public static function setUpBeforeClass()
 {
     $passwordHash = new Hash(Config::getInstance());
     $passwordHash->init('test');
     Db::setSetting('captcha', 1);
     Db::forTablePrefix('users')->whereIdIs(1)->findOne()->set('password', $passwordHash->getHash())->save();
 }
Пример #4
0
 /**
  * append the captcha
  *
  * @since 2.6.0
  *
  * @param string $type type of the captcha
  *
  * @return Form
  */
 public function captcha($type = null)
 {
     /* task */
     if ($type === 'task') {
         $this->label($this->_captcha->getTask(), array('for' => 'task'));
         /* number */
         $this->number(array('id' => 'task', 'min' => $this->_captcha->getMin(), 'max' => $this->_captcha->getMax() * 2, 'name' => 'task', 'required' => 'required'));
     }
     /* solution */
     if ($type === 'solution') {
         $captchaHash = new Hash(Config::getInstance());
         $captchaHash->init($this->_captcha->getSolution());
         /* hidden */
         $this->hidden(array('name' => 'solution', 'value' => $captchaHash->getHash()));
     }
     return $this;
 }
 /**
  * testGetHash
  *
  * @since 2.6.0
  *
  * @param string $raw
  * @param array $hashArray
  *
  * @dataProvider providerHash
  */
 public function testGetHash($raw = null, $hashArray = array())
 {
     /* setup */
     $hash = new Hash($this->_config);
     $hash->init($raw);
     /* expect and actual */
     $expect = function_exists('password_hash') ? $hashArray[0][0] : $hashArray[1];
     $actual = $hash->getHash();
     /* compare */
     if (function_exists('password_hash')) {
         $this->assertStringStartsWith($expect, $actual);
     } else {
         $this->assertEquals($expect, $actual);
     }
 }