Skip to content

Commit

Permalink
Merge pull request #672 from ashiina/hash_password
Browse files Browse the repository at this point in the history
Implemented method to override the password hashing algorithm
  • Loading branch information
bshaffer committed Jan 11, 2016
2 parents 0c1cb02 + df182af commit b9da77c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/OAuth2/Storage/Cassandra.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ public function checkUserCredentials($username, $password)
// plaintext passwords are bad! Override this for your application
protected function checkPassword($user, $password)
{
return $user['password'] == sha1($password);
return $user['password'] == $this->hashPassword($password);
}

// use a secure hashing algorithm when storing passwords. Override this for your application
protected function hashPassword($password)
{
return sha1($password);
}

public function getUserDetails($username)
Expand All @@ -204,7 +210,7 @@ public function getUser($username)

public function setUser($username, $password, $first_name = null, $last_name = null)
{
$password = sha1($password);
$password = $this->hashPassword($password);

return $this->setValue(
$this->config['user_key'] . $username,
Expand Down
10 changes: 8 additions & 2 deletions src/OAuth2/Storage/DynamoDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,13 @@ public function unsetRefreshToken($refresh_token)
// plaintext passwords are bad! Override this for your application
protected function checkPassword($user, $password)
{
return $user['password'] == sha1($password);
return $user['password'] == $this->hashPassword($password);
}

// use a secure hashing algorithm when storing passwords. Override this for your application
protected function hashPassword($password)
{
return sha1($password);
}

public function getUser($username)
Expand All @@ -363,7 +369,7 @@ public function getUser($username)
public function setUser($username, $password, $first_name = null, $last_name = null)
{
// do not store in plaintext
$password = sha1($password);
$password = $this->hashPassword($password);

$clientData = compact('username', 'password', 'first_name', 'last_name');
$clientData = array_filter($clientData, 'self::isNotEmpty');
Expand Down
10 changes: 8 additions & 2 deletions src/OAuth2/Storage/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,13 @@ public function unsetRefreshToken($refresh_token)
// plaintext passwords are bad! Override this for your application
protected function checkPassword($user, $password)
{
return $user['password'] == sha1($password);
return $user['password'] == $this->hashPassword($password);
}

// use a secure hashing algorithm when storing passwords. Override this for your application
protected function hashPassword($password)
{
return sha1($password);
}

public function getUser($username)
Expand All @@ -328,7 +334,7 @@ public function getUser($username)
public function setUser($username, $password, $firstName = null, $lastName = null)
{
// do not store in plaintext
$password = sha1($password);
$password = $this->hashPassword($password);

// if it exists, update it.
if ($this->getUser($username)) {
Expand Down

0 comments on commit b9da77c

Please sign in to comment.