I have a this credential:
username: pippo
password: 1234\zxcv
I need to generate base 64 encoding. The correct base 64 string is
I use btoa() but not convert correctly string. The problem is \ character. Ho can I escape it?
Thanks
Escape \
with \\
when user inputs \
character.
<form>
username: <input type="text" /><br />
password: <input type="password" /><br />
<input type="submit" />
</form>
<script>
var input = document.querySelector("input[type=password]");
input.oninput = function(e) {
if (e.target.value.slice(-1) === "\\") {
e.target.value = e.target.value.replace(/\\/g, "\\");
}
}
document.querySelector("input[type=submit]")
.onclick = function(e) {
e.preventDefault();
console.log(btoa(input.value), atob(btoa(input.value)));
}
</script>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments