public static function generate_jwt($user, $expire) { $issuedAt = time(); $tokenId = base64_encode(Random::key(32)); $serverName = Config::get('serverName'); /* * Create the token as an array */ $data = ['iat' => $issuedAt, 'jti' => $tokenId, 'iss' => $serverName, 'exp' => $expire, 'data' => ['userId' => $user->id, 'userName' => $user->username]]; /* * Extract the key, which is coming from the config file. * * Generated with base64_encode(openssl_random_pseudo_bytes(64)); */ $secretKey = base64_decode(ForumSettings::get('jwt_token')); /* * Extract the algorithm from the config file too */ $algorithm = ForumSettings::get('jwt_algorithm'); /* * Encode the array to a JWT string. * Second parameter is the key to encode the token. * * The output string can be validated at http://jwt.io/ */ $jwt = JWT::encode($data, $secretKey, $algorithm); return $jwt; }
public function create_config(array $data) { Container::get('hooks')->fire('controller.install.create_config'); // Generate config ... $config = array(); foreach ($data as $key => $value) { if (in_array($key, $this->config_keys)) { $config[$key] = $value; } } $config = array_merge($config, array('cookie_name' => mb_strtolower(ForumEnv::get('FORUM_NAME')) . '_cookie_' . Random::key(7, false, true), 'jwt_token' => base64_encode(Random::secure_random_bytes(64)), 'jwt_algorithm' => 'HS512')); // ... And write it on disk if ($this->write_config($config)) { return $this->create_db($data); } else { // TODO: Translate return Router::redirect(Router::pathFor('install'), ['error', 'Error while writing config file']); } }
public function create_config(array $data) { // Generate config ... $config = array(); foreach ($data as $key => $value) { if (in_array($key, $this->config_keys)) { $config[$key] = $value; } } $config = array_merge($config, array('cookie_name' => mb_strtolower($this->feather->forum_env['FORUM_NAME']) . '_cookie_' . Random::key(7, false, true), 'cookie_seed' => Random::key(16, false, true))); // ... And write it on disk if ($this->write_config($config)) { $this->create_db($data); } }
?> </span> </td> </tr> <tr> <th scope="row"><?php _e('SMTP password label'); ?> </th> <td> <label><input type="checkbox" name="form_smtp_change_pass" value="1" /> <?php _e('SMTP change password help'); ?> </label> <?php $smtp_pass = !empty(ForumSettings::get('o_smtp_pass')) ? Random::key(Utils::strlen(ForumSettings::get('o_smtp_pass')), true) : ''; ?> <input type="password" name="form_smtp_pass1" size="25" maxlength="50" value="<?php echo $smtp_pass; ?> " /> <input type="password" name="form_smtp_pass2" size="25" maxlength="50" value="<?php echo $smtp_pass; ?> " /> <span><?php _e('SMTP password help'); ?> </span> </td> </tr>
?> </span> </td> </tr> <tr> <th scope="row"><?php _e('SMTP password label'); ?> </th> <td> <label><input type="checkbox" name="form_smtp_change_pass" value="1" /> <?php _e('SMTP change password help'); ?> </label> <?php $smtp_pass = !empty($feather->forum_settings['o_smtp_pass']) ? Random::key(Utils::strlen($feather->forum_settings['o_smtp_pass']), true) : ''; ?> <input type="password" name="form_smtp_pass1" size="25" maxlength="50" value="<?php echo $smtp_pass; ?> " /> <input type="password" name="form_smtp_pass2" size="25" maxlength="50" value="<?php echo $smtp_pass; ?> " /> <span><?php _e('SMTP password help'); ?> </span> </td> </tr>