You are here

function aes_user in AES encryption 5

Same name and namespace in other branches
  1. 6 aes.module \aes_user()

File

./aes.module, line 237

Code

function aes_user($op, &$edit, &$account, $category = null) {
  if ($op == "view") {
    if (user_access('view passwords') && (variable_get("aes_viewing_method", "page") == "collapsible" || variable_get("aes_viewing_method", "page") == "both") && aes_password_exists($account->uid)) {
      $account->content['info']['aes_password'] = array(
        '#type' => 'user_profile_item',
        '#title' => t('Password'),
        '#value' => drupal_get_form('aes_view_password_form', aes_get_password($account->uid, true)),
      );
    }
  }
  if ($op == "login") {
    if (variable_get("aes_convert", "true") == "true" && aes_password_exists($account->uid) == false) {
      db_query("INSERT INTO {aes_passwords} (uid, pass) VALUES (%d, '%s')", $account->uid, aes_encrypt($edit['pass']));
    }
  }
  if ($op == "update" || $op == "insert") {
    if (!empty($edit['pass']) && $account->uid) {
      $password = aes_encrypt($edit['pass']);
      if (strlen($password) > AES_PASSWORD_MAX_LENGTH) {
        $edit['pass'] = null;
        drupal_set_message(t("Couldn't update AES password since it's too long.", "error"));
      }
      else {

        //if this user doesn't have a password and creation of enc passwords is enabled, insert one now
        if (aes_password_exists($account->uid) == false) {
          if (variable_get("aes_convert", "true") == "true") {
            db_query("INSERT INTO {aes_passwords} (uid, pass) VALUES (%d, '%s')", $account->uid, $password);
          }
        }
        else {
          db_query("UPDATE {aes_passwords} SET pass='%s' WHERE uid=%d", $password, $account->uid);
        }
      }
    }
  }
  if ($op == "delete") {
    db_query("DELETE FROM {aes_passwords} WHERE uid=%d", $account->uid);
  }
}