You are here

public function TfaBasicRecoveryCode::getCodes in TFA Basic plugins 7

Get unused recovery codes.

@todo consider returning used codes so validate() can error with appropriate message

Return value

array Array of codes indexed by ID.

2 calls to TfaBasicRecoveryCode::getCodes()
TfaBasicRecoveryCode::ready in includes/tfa_recovery.inc
@copydoc TfaBasePlugin::ready()
TfaBasicRecoveryCode::validate in includes/tfa_recovery.inc
@copydoc TfaBasePlugin::validate()

File

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

Class

TfaBasicRecoveryCode
Class TfaBasicRecoveryCode

Code

public function getCodes() {

  // Lookup codes for account and decrypt.
  $codes = array();
  $result = db_query("SELECT id, code FROM {tfa_recovery_code} WHERE uid = :uid AND used = 0", array(
    ':uid' => $this->context['uid'],
  ));
  if (!empty($result)) {
    foreach ($result as $data) {
      $encrypted = base64_decode($data->code);

      // trim() prevents extraneous escape characters.
      $code = trim($this
        ->decrypt($encrypted));
      if (!empty($code)) {
        $codes[$data->id] = $code;
      }
    }
  }
  return $codes;
}