简体   繁体   English

使用复选框切换密码输入(由于安全风险而无法使用)

[英]Toggle password input using a checkbox (not working due to security risks)

I'm trying to get rid of the "put your password in again to confirm it" field in my sign up form. 我正在尝试取消注册表单中的“再次输入密码以确认密码”字段。 The design pattern I've seen to get around this is a checkbox which will reveal the password to the user - so they can verify it. 我见过的设计模式是一个复选框,该复选框将向用户显示密码-以便他们可以进行验证。 However, implementing it seems to be a pain. 但是,实施它似乎很痛苦。

Here's my relevant html: 这是我相关的html:

          <form name="signup">
            <div class="form-group">
              <input id="usernameInput" class="form-control" placeholder="username">
            </div>
            <div class="form-group">
              <input type="email" id="emailInput" class="form-control" placeholder="email">
            </div>
            <div class="form-group">
              <input type="password" name="passwordInput" class="form-control" placeholder="password">
            </div>
            <div class="checkbox">
              <label>
                <input type="checkbox" name="show-pass" value='1' onchange="showPass()"> Show password
              </label>
            </div>
            <button type="submit" class="btn btn-info btn-lg">Sign Up</button>
            <a href="#" class="btn btn-primary btn-lg owl-next" role="button">Back</a>
          </form>

And the accompanying javascript: 以及随附的javascript:

function showPass() {
          document.signup.passwordInput.type=(document.signup.show-pass.value=(document.signup.show-pass.value==1)?'-1':'1')=='1'?'text':'password';
      }

However, when I try it in firefox, I get the following console error: 但是,当我在firefox中尝试时,出现以下控制台错误:

Password fields present on an insecure (http://) page. This is a security risk that allows user login credentials to be stolen.

The error is a little cryptic seeing as the issue isn't with having a password field on a non-https website (I had it working before). 该错误有点神秘,因为问题不在于非https网站上的密码字段(我之前曾使用过)。 Is there something I'm missing here? 我在这里想念什么吗?

If you have ever heard about jQuery use it, it will be easirer 如果您曾经听说过jQuery使用它,它将变得更加容易

$('#id-of-checkbox').change(function(){
 if($(this).is(':checked')){
  $('.password-fields').attr('type','text');
} else {
 $('.password-fields').attr('type','password');
}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM