Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make password textbox value visible after each character input

I have a password field :

 <input class="form-control" type="password" name="password" required="required" />

Naturally when user enters password,it's in ***** pattern by default,

but I want to add something different in this field means when user enters any of the character from the password it should show it for a while then transform it into ***.

I saw this thing in Iphone that when user enters passcode , the currently entered character is shown for a while then it just get transformed into ****. How can i do this in .net application ? Kindly someone help me to resolve this Thanks in advance.

like image 617
Alina Anjum Avatar asked May 12 '16 12:05

Alina Anjum


People also ask

How do you display a TextBox for accepting password character from the user?

To create a password text boxSet the PasswordChar property of the TextBox control to a specific character. The PasswordChar property specifies the character displayed in the text box. For example, if you want asterisks displayed in the password box, specify * for the PasswordChar property in the Properties window.

How can I access a value inside a TextBox that has a password as ID?

The input element with type=”password” can be accessed by using getElementById() method.

How do I show password in password field?

Right-click the password field and click Inspect Element. A gray bar will appear with the password field highlighted. Press Alt+M or click on the icon shown below to open the Markup Panel. It will show you the code for the password field.

What character is displayed on the password forms when the user inputs characters?

<input> elements of type password provide a way for the user to securely enter a password. The element is presented as a one-line plain text editor control in which the text is obscured so that it cannot be read, usually by replacing each character with a symbol such as the asterisk ("*") or a dot ("•").


3 Answers

This snippet will automatically convert your password input field to text field and one hidden field with same name as your password field

<input type="password" name="pass" class="pass" />

will converted to

<input type="text" class="pass" />
<input type="hidden" name="pass" class="hidpassw"/>

Here i haven't converted another to hidden for demo purpose. See if it works for you or not

function createstars(n) {
  return new Array(n+1).join("*")
}


$(document).ready(function() {

  var timer = "";

  $(".panel").append($('<input type="text" class="hidpassw" />'));

  $(".hidpassw").attr("name", $(".pass").attr("name"));

  $(".pass").attr("type", "text").removeAttr("name");

  $("body").on("keypress", ".pass", function(e) {
    var code = e.which;
    if (code >= 32 && code <= 127) {
      var character = String.fromCharCode(code);
      $(".hidpassw").val($(".hidpassw").val() + character);
    }


  });

  $("body").on("keyup", ".pass", function(e) {
    var code = e.which;

    if (code == 8) {
      var length = $(".pass").val().length;
      $(".hidpassw").val($(".hidpassw").val().substring(0, length));
    } else if (code == 37) {

    } else {
      var current_val = $('.pass').val().length;
      $(".pass").val(createstars(current_val - 1) + $(".pass").val().substring(current_val - 1));
    }

    clearTimeout(timer);
    timer = setTimeout(function() {
      $(".pass").val(createstars($(".pass").val().length));
    }, 200);

  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="panel">
  <input type="password" name="paswd" class="pass" />
</div>

While searching found a tutorial for creating a masked password field

Here is a jsbin link to working demo creating masked password field

Link to the tutorial for reference Tutorial

like image 77
Garvit Mangal Avatar answered Oct 22 '22 21:10

Garvit Mangal


Just an idea, you could add a hidden field holding your password while converting the visible input contents to dots.

var showLength = 3;
var delay = 1000;
var hideAll = setTimeout(function() {}, 0);

$(document).ready(function() {
  $("#password").on("input", function() {
    var offset = $("#password").val().length - $("#hidden").val().length;
    if (offset > 0) $("#hidden").val($("#hidden").val() + $("#password").val().substring($("#hidden").val().length, $("#hidden").val().length + offset));
    else if (offset < 0) $("#hidden").val($("#hidden").val().substring(0, $("#hidden").val().length + offset));

    // Change the visible string
    if ($(this).val().length > showLength) $(this).val($(this).val().substring(0, $(this).val().length - showLength).replace(/./g, "•") + $(this).val().substring($(this).val().length - showLength, $(this).val().length));

    // Set the timer
    clearTimeout(hideAll);
    hideAll = setTimeout(function() {
      $("#password").val($("#password").val().replace(/./g, "•"));
    }, delay);
  });
});
#hidden {
  opacity: 0.5;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="password" type="text" value="" />
<input id="hidden" type="text" value="" />
like image 44
PinkTurtle Avatar answered Oct 22 '22 21:10

PinkTurtle


You can use a Jquery plugin to accomplish this. Here's the link where you can get the plugin https://github.com/panzj/jquery-mobilePassword/blob/master/js/jquery.mobilePassword.js

Here is the code,

$(document).ready(function() {
        $("input[type=password]").mobilePassword();

    });

HTML code:

<input type="password" name = "password" id = "password" placeholder = "password" class ="input">
like image 2
Pragin M Avatar answered Oct 22 '22 23:10

Pragin M