我正在创建一个 html 表单来捕获申请人的输入,然后将 POST 请求发送到带有数据的 api。我不知道如何从“查看页面源代码”或 console.log() 之类的东西中隐藏三个特定值。我需要安全地存储这些值,并且仍然能够在 HTML 表单中使用它们。
我知道我可能不得不重写我的解决方案,但我不知道解决这个问题的最佳方法。有没有办法将 api 键的值存储在数据库中?
以下是有问题的三个值:
<body>
<main role="main" class="container-fluid">
<form id="form1" name="form1" onsubmit="beforeSubmit(); return false;">
<div class="aspNetHidden">
<input type="hidden" name="merchantID" id="merchantID" />
<input type="hidden" name="login" id="login" />
<input type="hidden" name="password" id="password" />
</div>
<script type="text/javascript">
var merID = "1234567";//need to store these values somewhere else!!!!!!!
var log = "API123";
var pass = "1234567";
//even if these values are moved they would be viewable by something like console.log(obj)
document.getElementById("merchantID").value = merID;
document.getElementById("login").value = log;
document.getElementById("password").value = pass;
</script>
这是我进行 API 调用的地方:
<script type="text/javascript">
beforeSubmit = function () {
//======================================================================================================
$.fn.serializeObject = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
我对此很陌生。除了通过检查页面源可以轻松查看敏感信息之外,该代码还执行它应该做的事情。任何关于更好/更安全方式的建议将不胜感激。