我的两阶段登录包括一个表单,其中输入了用户名和密码,该表单链接到第二个必须输入PIN码的表单。
所以;完整的表格1,提交,完整的表格2,允许提交和输入(取决于身份验证)。
问题是,表单2上的PINcode文本框是type ='text',因为我不希望在提交时显示“保存密码”对话框。而且,无论用户输入什么,我都希望掩盖不被窥探的眼睛。
永远不要保存PIN码。
大多数主浏览器都不需要JS。 Firefox 72没有。
我查看了其他“解决方案”,但它们是针对FF的旧版本的,因此我无法使其在FF72中工作。
为了使其他人的评论更加清晰... JS确保PIN被光盘掩盖,但是它以type ='password'的形式提交,从而抛出了我不想出现的“保存密码”对话框。
这是我的表格
window.onload = function(){
init();
}
function init(){
var x = document.getElementById("PINcode");
if( x ) {
x.setAttribute("type","password");
}else{
// do nothing
}
}
#PINcode {
text-security:disc;
-webkit-text-security:disc;
-moz-text-security:disc;
}
<form id='login-form-pin' class="form-signin" action="/$cp_location/pin-login.pl" method='post'>
<div>
<h1>WARNING:</h1>
<p>$active_text</p>
<label for="PINcode" class="sr-only">PIN Code</label>
<input type="text" id="PINcode" name='PINcode' class="form-control" placeholder="Enter your PIN" required />
<input class="btn btn-lg btn-primary btn-block" type="submit" name='Login' value="Enter your PIN" />
<input type='hidden' name='action' value='personal pin entry' />
<p>
<a href="/$cp_location/resend_login_pin.pl?user=$entered_user_name&action=resend_pin">Send me a new PIN.</a> <a href="/$cp_location/login.pl?logout=Logout">Force Log Out</a>
</p>
</div>
</form>
该JS在FF中没有任何视觉效果。
Autocomplete ='一次性代码'在这里没有用。它会弹出“保存密码”对话框。
[已编辑进度] 现在,表单元素如下:
<input type="text" id="user_pin_code" name='user_pin_code' class="form-control" placeholder="Enter your PIN" onkeyup="obfuscateEntry();" autocomplete='off' required />
我正在使用从另一个线程中发现的JS修改的
<script>
actualText = "";
function obfuscateEntry() {
var x = document.getElementById("user_pin_code").value;
var tempText = x.replace(/\\*/g,"");
console.log( 'x = ' + x );
if(tempText == "")
{
actualText = actualText.substr(0, actualText.length - 1);
}
else {
actualText += x.replace(/\\*/g,"");
}
document.getElementById("user_pin_code").value = "";
for (var i=0;i<x.length;i++)
{
document.getElementById("user_pin_code").value += "*";
document.getElementById("PINcode").value = actualText;
}
}
[/ edit]
剩下的唯一问题是,如果PIN码输入速度太快,脚本可能会漏掉某些字符。我认为这需要一个单独的问题,所以我为其他人发布了“解决方案”。