JSFiddle - React, Tailwind, and code Playground
by Ayyappan Sakthivadivel
HTML
<input type="text" id="pass" onkeyup="mask(this.value)"/>
<input type="button" onclick="getPassword()" value="Show Password"/>
JavaScript
var password = '';
function mask(str) {
num = str.length;
password += (num == 1) ? str.substr(0,1) : str.substr(num-1, num);
first = password.substr(0,1);
last = password.substr(num-1, num);
masked = first;
for(i=0; i<num-2; i++) {
masked += '*';
}
masked += (num ==1) ? '' : last;
document.getElementById("pass").value = masked;
}
function getPassword() {
alert(password);
}