You are here

function MoAuthPasswordValidator::lastNPasswordsInDB in Google Authenticator / 2 Factor Authentication - 2FA 7

1 call to MoAuthPasswordValidator::lastNPasswordsInDB()
MoAuthPasswordValidator::isPasswordUnique in classes/MoAuthPasswordValidator.php

File

classes/MoAuthPasswordValidator.php, line 33

Class

MoAuthPasswordValidator

Code

function lastNPasswordsInDB() {
  $result = db_query('Select * from {mo_auth_user_track} where uid=' . $this->user->uid)
    ->fetchAllAssoc('id');
  if (!$this
    ->isLastPasswordInserted($result)) {

    // insert the last password
    $loginSettings = new MoAuthLoginSettings();

    // remove last password
    $minId = db_query('select min(id) from {mo_auth_user_track} where uid=' . $this->user->uid)
      ->fetchCol();
    if (count($result) >= $loginSettings
      ->getLastNUniquePassword()) {
      db_query('delete from {mo_auth_user_track} where uid=' . $this->user->uid . ' and id=' . $minId[0])
        ->execute();
    }
    db_insert('mo_auth_user_track')
      ->fields(array(
      'uid' => $this->user->uid,
      'pass' => $this->user->pass,
    ))
      ->execute();
    $currentPassword = new stdClass();
    $currentPassword->id = -1;
    $currentPassword->uid = $this->user->uid;
    $currentPassword->pass = $this->user->pass;
    array_push($result, $currentPassword);
  }
  return $result;
}