Frederico Falcao f2a6525224 init
2025-05-30 10:46:17 +01:00

46 lines
1.4 KiB
PHP

<?php
/*
* FILE: 03_handler.php
* Description: Handles the input provided from the browser/user
*/
/* Bring the key/file into local scope */
$pwFile = $passwordFile; // from constants
$key = $passwordKey; // static, can be ""
/* ---------- DELETE PASSWORD ---------- */
if (isset($_POST['delete_idx'])) {
$idx = (int)$_POST['delete_idx'];
$pwList = getPasswordList($pwFile, $key);
if (isset($pwList[$idx])) {
array_splice($pwList, $idx, 1);
savePasswordList($pwFile, $pwList, $key);
}
header("Location: ".$_SERVER['REQUEST_URI']); exit;
}
/* ---------- GENERATE PASSWORD BUTTON ---------- */
if (isset($_POST['generate_password'])) {
$_POST['password'] = generatePassword(16);
}
/* ---------- ADD / UPDATE PASSWORD ---------- */
if (isset($_POST['add_password'])) {
$pwList = getPasswordList($pwFile, $key);
$pwList[] = [
'site' => trim($_POST['site']),
'username' => trim($_POST['username']),
'password' => $_POST['password'],
'otp_secret' => trim($_POST['otp_secret'] ?? ''),
'cc_number' => trim($_POST['cc_number'] ?? ''),
'cc_exp' => trim($_POST['cc_exp'] ?? ''),
'ccv' => trim($_POST['ccv'] ?? ''),
'monthly' => trim($_POST['monthly'] ?? ''),
];
savePasswordList($pwFile, $pwList, $key);
header("Location: ".$_SERVER['REQUEST_URI']); exit;
}
?>