Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

372
Vistas
when I hash my password on the client side , I am not getting the hashed string instead getting the password itself

I am trying to hash my password on the client-side before sending it to my server(Tomcat server), when I click on submit the form is getting submitted before updating the value of the password to hashcode how can I make sure That my form gets submitted after the script is executed? or is there a better way to go by this?

<html>
<head>
    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, 
initial-scale=1.0">
</head>
<body>
    <h1></h1>
    <form method="post" onsubmit="encrypt(event);" action="login" >
        <input type="text" name="user_id">
        <input type="password" name="password" id="pass">
        <button id="but1" type="submit">submit</button>
    </form>
    <script>
function encrypt(event){
//  event.preventDefault();//prevents from form getting auto submitted              
document.querySelector("body").style.color="red";             
sha512(document.getElementById("pass").value).then((x)=> 
{                
document.getElementById("pass").value=x;                   
document.querySelector("h1").innerHTML = x;
});
}


            function sha512(str) {
            return crypto.subtle.digest("SHA-512", new TextEncoder("utf- 
8").encode(str)).then(buf => {
            return Array.prototype.map.call(new Uint8Array(buf), x=> 
(('00'+x.toString(16)).slice(-2))).join('');
            });
            }
            sha512("my string for hashing").then(x => console.log(x)); 
    </script>
  </body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Submit your form after the process

 <form id="form1" method="post" onsubmit="encrypt(event);" action="login" >
        <input type="text" name="user_id">
        <input type="password" name="password" id="pass">
        <button id="but1" type="submit">submit</button>
    </form>


function encrypt(event) {
  event.preventDefault(); //prevents from form getting auto submitted
  document.querySelector("body").style.color = "red";
  sha512(document.getElementById("pass").value).then((x) => {
    document.getElementById("pass").value = x;
    document.querySelector("h1").innerHTML = x;
    document.getElementById("form1").submit(); // submitting the form
  });
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda