/** * Generates a new token. * * @access protected * @return string */ protected function generateToken() { if (!$this->exists) { throw new LogicException(vsprintf("%s(): You can only generate auth tokens for users that exist in the database.", [__METHOD__])); } return hash('sha256', UUID::v4() . $this->getId() . uniqid('token', true)); }
/** * Generates a session id. * * @access protected * @return string */ protected function generateId() { return hash('sha256', UUID::v4() . uniqid('session', true)); }
/** * Checks that the field value is a valid UUID. * * @access protected * @param string $input Field value * @return boolean */ protected function validateUuid($input) { return UUID::validate($input); }
/** * */ public function testUUIDKey() { $uuid = UUIDKey::create(['value' => 'foo']); $this->assertTrue(UUID::validate($uuid->id)); $uuid = UUIDKey::first(); $this->assertTrue(UUID::validate($uuid->id)); }
/** * Inserts a new record into the database. * * @access protected * @param \mako\database\midgard\Query $query Query builder */ protected function insertRecord($query) { if ($this->primaryKeyType === static::PRIMARY_KEY_TYPE_INCREMENTING) { $this->columns[$this->primaryKey] = $query->insertAndGetId($this->columns, $this->primaryKey); } else { switch ($this->primaryKeyType) { case static::PRIMARY_KEY_TYPE_UUID: $this->columns[$this->primaryKey] = UUID::v4(); break; case static::PRIMARY_KEY_TYPE_CUSTOM: $this->columns[$this->primaryKey] = $this->generatePrimaryKey(); break; } $query->insert($this->columns); } }
/** * @expectedException \InvalidArgumentException */ public function testV5WithInvalidNamespace() { UUID::v5('nope', 'foobar'); }