我可以将hash(sha1)添加到输入值以比较两个输入吗?

时间:2017-10-10 07:26:03

标签: javascript php

我一直在尝试比较两个输入。

第一个输入是“隐藏”类型并从数据库中获取值。

对于第二个输入 - 值插入客户,但只有与数据库中的相同,才能更新他的数据。 这是php:

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

和脚本:

<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>

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

我不认为在Javascript中这样做是个好主意。你有点像这样给用户密码的方式。还有隐藏字段,密码为值?不好!<​​/ p>

将所有这些移到php中。让该人首先写入密码,在php中比较它,然后更新信息。如果您想在一个页面中执行此操作,请使用ajax。