You are here

protected function TfaBasicRecoveryCodeSetup::storeCodes in TFA Basic plugins 7

Save codes for account.

Parameters

array $codes:

1 call to TfaBasicRecoveryCodeSetup::storeCodes()
TfaBasicRecoveryCodeSetup::submitSetupForm in includes/tfa_recovery.inc
@copydoc TfaSetupPluginInterface::submitSetupForm()

File

includes/tfa_recovery.inc, line 247
class for TFA Basic

Class

TfaBasicRecoveryCodeSetup
Class TfaBasicRecoveryCode

Code

protected function storeCodes($codes) {
  $num_deleted = $this
    ->deleteCodes();

  // Encrypt code for storage.
  foreach ($codes as $code) {
    $encrypted = $this
      ->encrypt($code);

    // Data is binary so store base64 encoded.
    $record = array(
      'uid' => $this->context['uid'],
      'code' => base64_encode($encrypted),
      'created' => REQUEST_TIME,
    );
    drupal_write_record('tfa_recovery_code', $record);
  }
  $message = 'Saved recovery codes for user !uid';
  if ($num_deleted) {
    $message .= ' and deleted !del old codes';
  }
  watchdog('tfa_basic', $message, array(
    '!uid' => $this->context['uid'],
    '!del' => $num_deleted,
  ), WATCHDOG_INFO);
}