function aes_config_submit in AES encryption 5
Same name and namespace in other branches
- 6 aes.module \aes_config_submit()
- 7 aes.admin.inc \aes_config_submit()
File
- ./aes.module, line 146
Code
function aes_config_submit($form, &$form_state) {
if ($form_state['values']['aes_convert']) {
if (variable_get("aes_convert", "true") == "false") {
variable_set("aes_convert", "true");
drupal_set_message(t("Creation of encrypted passwords enabled."));
}
}
else {
if (variable_get("aes_convert", "true") == "true") {
variable_set("aes_convert", "false");
drupal_set_message(t("Creation of encrypted passwords disabled."));
}
}
variable_set("aes_key_path", $form_state['values']['aes_key_path']);
if ($form_state['values']['aes_key_storage_method'] != variable_get("aes_key_storage_method", "")) {
drupal_set_message(t("Switching key storage method to !method.", array(
'!method' => $form_state['values']['aes_key_storage_method'],
)));
$key = aes_get_key();
aes_delete_key(variable_get("aes_key_storage_method", ""));
variable_set("aes_key_storage_method", $form_state['values']['aes_key_storage_method']);
aes_store_key($key);
}
if ($form_state['values']['aes_cipher'] != variable_get("aes_cipher", "rijndael-128")) {
$result = db_query("SELECT uid, pass FROM {aes_passwords} WHERE uid != 0");
$old_cipher = variable_get("aes_cipher", "rijndael-128");
variable_set("aes_cipher", $form_state['values']['aes_cipher']);
$new_cipher = $form_state['values']['aes_cipher'];
$old_iv = variable_get("aes_encryption_iv", "");
variable_set("aes_cipher", $form_state['values']['aes_cipher']);
aes_make_iv();
$new_iv = variable_get("aes_encryption_iv", "");
$updates_num = 0;
while ($user = db_fetch_array($result)) {
$plain_pass = trim(aes_decrypt($user['pass'], true, null, $old_cipher, $old_iv));
$new_pass = aes_encrypt($plain_pass, true, null, $new_cipher, $new_iv);
$updates_num++;
db_query("UPDATE {aes_passwords} SET pass='%s' WHERE uid=%d", $new_pass, $user['uid']);
}
drupal_set_message(t("Updated the passwords of !updates_num users because of a change in cipher.", array(
'!updates_num' => $updates_num,
)));
}
if (!empty($form_state['values']['aes_key'])) {
$old_key = aes_get_key();
$result = aes_store_key($form_state['values']['aes_key']);
if ($result === false) {
drupal_set_message(t("Failed to write new encryption key! Aborting."));
return;
}
drupal_set_message(t("Key changed."));
$a = db_query("SELECT uid, pass FROM {aes_passwords} WHERE uid != 0");
$updates_num = 0;
while ($user = db_fetch_array($a)) {
$plain_pass = trim(aes_decrypt($user['pass'], true, $old_key));
$new_pass = aes_encrypt($plain_pass, true, $form_state['values']['aes_key']);
$updates_num++;
db_query("UPDATE {aes_passwords} SET pass='%s' WHERE uid=%d", $new_pass, $user['uid']);
}
drupal_set_message(t("Updated the passwords of !updates_num users because of a change in key.", array(
'!updates_num' => $updates_num,
)));
}
variable_set("aes_viewing_method", $form_state['values']['view_method']);
}