2012-03-20 150 views
2

使用哈希SHA-512验证数据库中密码的形式验证密码我试图做的是专门用于更改密码表单。使用哈希sha-512验证数据库中密码的密码sha-512

我可以验证,如果在表单和数据库中的密码没有加密...但我没有验证输入的密码等于数据库密码,因为输入的密码仍然是正常形式,并且数据库内的密码是加密的一个。

我想使用jQuery验证功能......但坚持如何通过在提交之前用数据库加密输入的密码来解决。

回答

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部分(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; 
?>