Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Gravatar hashing to use sha256 (tests fixed) #159

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ Avatar::create('Susilo Bambang Yudhoyono')->save('sample.jpg', 100); // quality
### Output as Gravatar
```php
Avatar::create('uyab@example.net')->toGravatar();
// Output: http://gravatar.com/avatar/0dcae7d6d76f9a3b14588e9671c45879
// Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee

Avatar::create('uyab@example.net')->toGravatar(['d' => 'identicon', 'r' => 'pg', 's' => 100]);
// Output: http://gravatar.com/avatar/0dcae7d6d76f9a3b14588e9671c45879?d=identicon&r=pg&s=100
// Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee?d=identicon&r=pg&s=100
```
Gravatar parameter reference: https://en.gravatar.com/site/implement/images/
Gravatar parameter reference: https://docs.gravatar.com/api/avatars/images/

### Output as SVG
```php
Expand Down
4 changes: 2 additions & 2 deletions src/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ public function toSvg(): string

public function toGravatar(array $param = null): string
{
// Hash generation taken from https://en.gravatar.com/site/implement/images/php/
$hash = md5(strtolower(trim($this->name)));
// Hash generation taken from https://docs.gravatar.com/api/avatars/php/
$hash = hash('sha256', strtolower(trim($this->name)));

$attributes = [];
if ($this->width) {
Expand Down
10 changes: 5 additions & 5 deletions tests/AvatarPhpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public function it_can_handle_html_entities()
*/
public function it_can_generate_gravatar()
{
$expected = 'https://www.gravatar.com/avatar/0dcae7d6d76f9a3b14588e9671c45879?s=88';
$expected = 'https://www.gravatar.com/avatar/db6f5ab11fb203026beb0e298930cc5a07080022e7cbb4c597b97321585df61b?s=88';

$avatar = new \Laravolt\Avatar\Avatar();
$url = $avatar
Expand All @@ -402,7 +402,7 @@ public function it_can_generate_gravatar()
*/
public function it_can_generate_gravatar_with_size()
{
$expected = 'https://www.gravatar.com/avatar/0dcae7d6d76f9a3b14588e9671c45879?s=100';
$expected = 'https://www.gravatar.com/avatar/db6f5ab11fb203026beb0e298930cc5a07080022e7cbb4c597b97321585df61b?s=100';

$avatar = new \Laravolt\Avatar\Avatar();
$url = $avatar->create('uyab.exe@gmail.com')
Expand All @@ -417,7 +417,7 @@ public function it_can_generate_gravatar_with_size()
*/
public function it_can_generate_gravatar_with_default()
{
$expected = 'https://www.gravatar.com/avatar/0dcae7d6d76f9a3b14588e9671c45879?d=identicon&s=100';
$expected = 'https://www.gravatar.com/avatar/db6f5ab11fb203026beb0e298930cc5a07080022e7cbb4c597b97321585df61b?d=identicon&s=100';

$avatar = new \Laravolt\Avatar\Avatar();
$url = $avatar->create('uyab.exe@gmail.com')
Expand All @@ -432,7 +432,7 @@ public function it_can_generate_gravatar_with_default()
*/
public function it_can_generate_gravatar_with_default_and_rating()
{
$expected = 'https://www.gravatar.com/avatar/0dcae7d6d76f9a3b14588e9671c45879?d=identicon&r=pg&s=100';
$expected = 'https://www.gravatar.com/avatar/db6f5ab11fb203026beb0e298930cc5a07080022e7cbb4c597b97321585df61b?d=identicon&r=pg&s=100';

$avatar = new \Laravolt\Avatar\Avatar();
$url = $avatar->create('uyab.exe@gmail.com')
Expand All @@ -447,7 +447,7 @@ public function it_can_generate_gravatar_with_default_and_rating()
*/
public function it_can_generate_gravatar_with_size_overriden()
{
$expected = 'https://www.gravatar.com/avatar/0dcae7d6d76f9a3b14588e9671c45879?s=300';
$expected = 'https://www.gravatar.com/avatar/db6f5ab11fb203026beb0e298930cc5a07080022e7cbb4c597b97321585df61b?s=300';

$avatar = new \Laravolt\Avatar\Avatar();
$url = $avatar->create('uyab.exe@gmail.com')
Expand Down
Loading