/** * Check if token is valid. * * @return boolean true if token is valid */ public function isValidToken() { if (Security::isValidToken($this->token, $this->module->emailWithin) === true) { return ($this->_model = static::findOne(['token' => $this->token])) !== null; } return false; }
/** * Check if secure key is valid. * * @return boolean true if secure key is valid */ public function isValidSecureKey() { if (Security::isValidToken($this->secure_key, $this->module->recoveryWithin) === true) { return ($this->_user = User::findBySecureKey($this->secure_key, 'active')) !== null; } return false; }
/** * @return string SQL to insert first user */ private function getUserSql() { $time = time(); $password_hash = Yii::$app->security->generatePasswordHash('admin12345'); $auth_key = Yii::$app->security->generateRandomString(); $token = Security::generateExpiringRandomString(); return "INSERT INTO {{%users}} (username, email, password_hash, auth_key, token, role, status_id, created_at, updated_at) VALUES ('admin', '*****@*****.**', '{$password_hash}', '{$auth_key}', '{$token}', 'superadmin', 1, {$time}, {$time})"; }
/** * @return string SQL to insert first user */ private function getUserSql() { $time = time(); $password_hash = Yii::$app->security->generatePasswordHash('admin12345'); $auth_key = Yii::$app->security->generateRandomString(); $token = Security::generateExpiringRandomString(); return "INSERT INTO {{%users}} (`username`, `email`, `password_hash`, `auth_key`, `token`, `role`, `status_id`, `created_at`, `updated_at`) VALUES ('admin', '*****@*****.**', '{$password_hash}', '{$auth_key}', '{$token}', 'superadmin', 1, {$time}, {$time})"; }
/** * Send a recovery password token. * * @return boolean true if recovery token was successfully sent */ public function recovery() { $this->_model = User::findByEmail($this->email, 'active'); if ($this->_model !== null) { $this->_model->token = Security::generateExpiringRandomString(); $this->_model->save(); return $this->send(); } return false; }
/** * Generates secure key. */ public function generateToken() { $this->token = Security::generateExpiringRandomString(); }
/** * Generates secure key. */ public function generateSecureKey() { $this->secure_key = Security::generateExpiringRandomKey(); }
public function generateAccessToken() { $this->access_token = Security::generateExpiringRandomString(); }