简体   繁体   English

我可以将哈希(sha1)添加到输入的值中以比较两个输入吗?

[英]Can I add hash (sha1) to value from input for compare two inputs?

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:这是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.任何帮助将非常感激。

I don`t think its a good idea to do that in Javascript.我认为在 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.将所有这些移动到 php.ini 中。 Make the person first write the password, compare it in php and than update the info.让这个人先写密码,在php中进行比较,然后更新信息。 If you want to do it in one page, use ajax.如果要在一页中完成,请使用ajax。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM