我已经创建了这个密码类,如下所示:
<?php
namespace lib\Api;
class Password{
private $password;
private $salt;
private $hash;
public function __construct($password,$salt = ""){
$this->password = $password;
$this->salt = $salt;
$this->generateHash($this->password,$this->salt);
}
public function generateHash($password,$salt = ""){
$this->hash = hash('sha256',$password.$salt);
return $this->hash;
}
public function get(){
return $this->hash;
}
public function equals($password){
if($this->hash == $password){
return true;
}
return false;
}
}
?>
所以我使用它在user.php
文件/类
$this->password = (new Password($password,$this->getSalt()))->get();
,我也在login.php
文件/类
if((new Password($this->password,$salt))->equals($password)){
return true;
}
return false;
。现在我知道,如果你对它所依赖的东西进行散列,它是如何散列它的值。在这个典型的案例中,它让我非常困惑,因为我在password.php
文件/类中正式哈希。这是如何工作的,我怎样才能轻松妥善地解决它?
答案 0 :(得分:0)
很难理解你所问的是什么,但我敢打赌,在你检查它的平等之前,你想要哈希值$ password。
public class SeniorWorker extends RegularWorker {
public double meritPay;
public SeniorWorker(String name, double salary,double overtimePay, double meritPay)
{
super(name,salary,overtimePay);
this.meritPay = meritPay;
}
public double getMeritPay() {
return meritPay;
}
public void calculateMeritPay(){
meritPay = 0.10 * salary;
}
public double earnings() { return salary + overtimePay + meritPay; } //override the method to return salary
public String toString() { //override the method to print the name
return "Senior Worker: " + getName();
}
}