使用Hash sha-512在数据库中使用加密密码验证表单中的密码

时间:2012-03-20 06:56:35

标签: jquery encryption passwords password-encryption

使用散列SHA-512在数据库中使用加密密码验证密码,我正在尝试做的是专门用于更改密码表单。

我可以验证表单和数据库中的密码是否未加密...但是我无法验证输入的密码是否等于数据库密码,因为输入的密码仍然是正常形式,而数据库中的密码是加密的。

我想使用jQuery验证功能...但是在提交之前通过加密输入的密码来解决如何解决问题。

2 个答案:

答案 0 :(得分:2)

function Validate(data)
{
  if(data==true)
  {
   //submit the form
  }
  else
  {
   //dont submit the form. Throw an error/alert
   return false;
  }
}

//when the form is submitted
$("#yourForm").submit(function()
{
var p=$("#oldPassword").val();
$.post("validate.php",{oldpass:p},Validate);
});

PHP Part(validate.php)

<?php

$oldpassword=$_POST['oldpass'];

//encrypt $oldpassword to md5 or anything as per your requirement
//and compare it with the encrypted password available in the database

if($oldpassword==$dbpass)
{
   $status=true;
}
else
{
   $status=false;
}

echo $status;
?>

答案 1 :(得分:0)

function Validate(data)

这绝对不是他要求的......你有没有看过他的问题?很可能不是。

http://jssha.sourceforge.net/

http://pajhome.org.uk/crypt/md5/sha512.html

相关问题