Forum Discussion
Converting input text to a password icon/asterisk as you type?
Hello: can this be done?: Id like a user to type a password into a box. As they type, the letter are instantly concerted to small circles or asterisks as happe d when you enter a password in a site online. I thought about trying to use a mask to uncover the circles/asterisks but haven't had any luck. Any ideas? Thanks!
14 Replies
- WaltHamiltonSuper Hero
It seems to me that your idea of using a mask has worked before. Perhaps an easier method, if you can get it to work, is to format the box to a different font. There are fonts out there that are all asterisks, or maybe a symbols font would work.
- ToddBearsonCommunity Member
Found a font called Password Text." Works great -thanks!
- WaltHamiltonSuper HeroYou're welcome. PIAWYC (Pass it along when you can).
- Jean-Guy-BoulayCommunity Member
EDIT: ignore this reply below and JUMP to this part of the thread for a template.
Execute a javascript when the textEntry changes:
var player = GetPlayer();
const password = player.GetVar("textEntry");
const maskedString = "*".repeat(password.length);
player.SetVar("textEntry", maskedString);- CorporateTra830Community Member
I tried this is not working.
- NedimCommunity Member
Try this when the timeline starts:
var input = document.querySelector('.acc-textinput'); input.addEventListener("keydown", function () { let length = input.value.length; input.value = "*".repeat(length); });
- PhilMayorSuper Hero
This has two ways of doing it, first one modifies Nedims to use '•' instead, the second uses Jean's but I added in a keydown function so updates in realtime, Nedim's is best version but this adds a • instead, either of the values get lost as soon as you execute the code.
- Jean-Guy-BoulayCommunity Member
Sorry Guys for my previous post, PhilMayor 's post is a great template. I tried incorporating blur and focus before and could never get it to work properly. 👍 PhilMayor I added a 3rd slide that utitlizes the generic * of Nedim's code and incorporates a preventdefault that my project required. Slide 3 will completely hide what you are typing and incorporate the backspace and delete.
- NedimCommunity Member
PhilMayor Jean-Guy-Boulay For me, neither version works as expected. Ideally, this would function perfectly if we could convert the input type to "password". When typing a password on a typical web form, pressing navigation keys like the arrow keys (left, right, up, down) doesn’t add characters to the input. They just perform their default behavior, such as moving the cursor.
The same goes for modifier keys like Shift, Ctrl, or Alt. They should not affect the input value.
To improve this, we could store a copy of the actual value typed before it’s converted to asterisks (*). This would allow us to validate what the learner really entered and potentially offer an option to reveal or retrieve the password if it's forgotten.
Here is my final script to simulate exactly that in the attached example.const input = document.querySelector('.acc-textinput'); let rawValue = getVar("RawPassword") || ""; input.addEventListener("keydown", function(event) { const key = event.key; let maskedValue = getVar("MaskedPassword") || ""; const navigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Tab", "Enter", "Home", "End"]; if (navigationKeys.includes(key)) { return; } event.preventDefault(); if (key === "Backspace" || key === "Delete") { rawValue = rawValue.slice(0, -1); } else if (key.length === 1) { rawValue += key; } maskedValue = "*".repeat(rawValue.length); input.value = maskedValue; setVar("MaskedPassword", maskedValue); setVar("RawPassword", rawValue); });
- PhilMayorSuper Hero
Thanks Nedin, I still prefer a dot but very simple to implement. I quickly reused a blur trigger I wrote. And then wanted to add a save before but got lazy. Thanks for going the extra mile.
Related Content
- 10 months ago