2012-03-20 142 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; 
?>