2017-06-20 106 views
1

我目前正在構建一個與更大的應用程序(Zend 1.x)一起工作的應用程序(使用Laravel)。Laravel護照自定義散列機制

我正在使用Laravel護照進行API身份驗證。我需要將Laravel Passport默認哈希機制更改爲Zend哈希以使驗證工作。

有人可以指向一個API或我需要重寫以獲得此運行的東西嗎?我更喜歡不編輯核心Laravel Passport代碼。

我見過創建自定義用戶提供者和修改validateCredentials()方法的建議,但這些都是針對核心Laravel的。

我已經在用戶類中使用findForPassport方法來覆蓋用戶名字段。

public function findForPassport($username) 
{ 
    return $this->where('email', $username)->first(); 
} 

回答

1

大家很奇怪,可以覆蓋2種方法(也許更多)的用戶類來處理定製Laravel Passport身份驗證:

/** 
* Override the field which is used for username in the authentication 
*/ 
public function findForPassport($username) 
{ 
    return $this->where('email', $username)->first(); 
} 

/** 
* Add a password validation callback 
* 
* @param type $password 
* @return boolean Whether the password is valid 
*/ 
public function validateForPassportPasswordGrant($password) 
{ 
    $hasher = new HSAUserHasher(); // Or whomever does your hashing 

    $result = $hasher->create_hash($password, $this->salt); 
    $hashedPassword = $result['password']; 

    return $hashedPassword == $this->password; 
} 

由於@redviking在Laravel鬆弛論壇(https://larachat.slack.com)幫助我找到答案。