Decrease length of old tokens to 6 chars

[MAILPOET-2364]
This commit is contained in:
Rostislav Wolny
2019-09-17 14:25:15 +02:00
committed by Jack Kitterhing
parent 5cbcefbbb4
commit 7ea33310e8
2 changed files with 7 additions and 2 deletions

View File

@ -38,7 +38,9 @@ class Subscriber extends Model {
const STATUS_BOUNCED = 'bounced'; const STATUS_BOUNCED = 'bounced';
const STATUS_INACTIVE = 'inactive'; const STATUS_INACTIVE = 'inactive';
const DEPRECATED_LINK_TOKEN_LENGTH = 6;
const LINK_TOKEN_LENGTH = 32; const LINK_TOKEN_LENGTH = 32;
/** @var string|bool */ /** @var string|bool */
public $token; public $token;
@ -121,7 +123,10 @@ class Subscriber extends Model {
return self::where('wp_user_id', $wp_user->ID)->findOne(); return self::where('wp_user_id', $wp_user->ID)->findOne();
} }
static function generateToken($email = null, $length = 32) { /**
* @deprecated Only for backward compatibility for old tokens
*/
static function generateToken($email = null, $length = self::DEPRECATED_LINK_TOKEN_LENGTH) {
if ($email !== null) { if ($email !== null) {
$auth_key = ''; $auth_key = '';
if (defined('AUTH_KEY')) { if (defined('AUTH_KEY')) {

View File

@ -674,7 +674,7 @@ class SubscriberTest extends \MailPoetTest {
function testItGeneratesSubscriberToken() { function testItGeneratesSubscriberToken() {
$token = Subscriber::generateToken($this->test_data['email']); $token = Subscriber::generateToken($this->test_data['email']);
expect(strlen($token))->equals(32); expect(strlen($token))->equals(6);
} }
function testItVerifiesSubscriberToken() { function testItVerifiesSubscriberToken() {