This is my code to hash
class hashing {
private static $algo='$2a';
private static $cost='$10';
public static function unique_salt() {
return substr(sha1(mt_rand()),0,22);
}
function hash($password) {
return crypt($password,self::$algo.self::$cost.'$'.self::unique_salt());
}
public static function check_password($hash,$password) {
$full_salt=substr($hash,0,29);
$new_hash=crypt($password,$full_salt);
return ($hash==$new_hash);
}
}
This is my login page
require("hashing.php");
$password=hashing::hash($_POST['txtPassword']);
$checkPassword=mysql_query("SELECT * from $tbl_name WHERE Password='".$password."'");
$resultPassword=mysql_fetch_row($checkPassword);
if(hashing::check_password($resultPassword['Password'],$_POST['txtPassword'])) {
echo "login success!";
}
else {
echo "login failed!";
}
When the user inputs correct password, it is failing to login. How do I solve this problem?