javascript - Can I add hash (sha1) to value from input for compare two inputs?

840

I've been trying to compare two inputs.

First input is type "hidden" and get value from database.

For second input - value insert customer, but only if is same as in database, can her update his data. Here is php:

<input id="pass1" type="hidden" value= "'.$row_pswd['pswd'].'" />
<input id="pass2" type="password" placeholder="password" required />

and script:

<script>
function myFunction() {
var pass1 = document.getElementById("pass1").value;
var pass2 = document.getElementById("pass2").<?php echo SHA1("value"."t&#sdhstöksdf54gh"); ?>;
var ok = true;
if (pass1 != pass2) {
    alert("Passwords Do not match");
    document.getElementById("pass2").style.borderColor = "#E34234";
    ok = false;
}
else {
    alert("Passwords Match!!!");
}
return ok;
}
</script>

Any help would be much appreciated.

954

Answer

Solution:

I don`t think its a good idea to do that in Javascript. You kinda giving the way user password this way. Also hidden field with the password as value? Not good!

Move all this into php. Make the person first write the password, compare it in php and than update the info. If you want to do it in one page, use ajax.

People are also looking for solutions to the problem: javascript - Preshtashop 1.7.2 ajax call NetworkError: 500 Internal Server Error

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.