2017-06-25 00:49:09 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-06-25 00:49:09 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-06-25 00:49:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Helpers;
|
|
|
|
|
2018-03-05 04:42:33 +00:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2017-06-25 00:49:09 +00:00
|
|
|
use Illuminate\Contracts\Hashing\Hasher;
|
2017-09-27 03:16:26 +00:00
|
|
|
use Illuminate\Database\ConnectionInterface;
|
2017-06-25 00:49:09 +00:00
|
|
|
|
|
|
|
class TemporaryPasswordService
|
|
|
|
{
|
|
|
|
const HMAC_ALGO = 'sha256';
|
|
|
|
|
|
|
|
/**
|
2017-09-27 03:16:26 +00:00
|
|
|
* @var \Illuminate\Database\ConnectionInterface
|
2017-06-25 00:49:09 +00:00
|
|
|
*/
|
2017-09-27 03:16:26 +00:00
|
|
|
protected $connection;
|
2017-06-25 00:49:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Hashing\Hasher
|
|
|
|
*/
|
|
|
|
protected $hasher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TemporaryPasswordService constructor.
|
|
|
|
*
|
2017-09-27 03:16:26 +00:00
|
|
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
|
|
|
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
|
2017-06-25 00:49:09 +00:00
|
|
|
*/
|
2018-03-05 04:42:33 +00:00
|
|
|
public function __construct(ConnectionInterface $connection, Hasher $hasher)
|
|
|
|
{
|
2017-09-27 03:16:26 +00:00
|
|
|
$this->connection = $connection;
|
2017-06-25 00:49:09 +00:00
|
|
|
$this->hasher = $hasher;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a password reset token for a specific email address.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param string $email
|
2017-06-25 00:49:09 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2017-09-27 03:16:26 +00:00
|
|
|
public function handle($email)
|
2017-06-25 00:49:09 +00:00
|
|
|
{
|
2018-03-05 04:42:33 +00:00
|
|
|
$token = hash_hmac(self::HMAC_ALGO, Uuid::uuid4()->toString(), config('app.key'));
|
2017-06-25 00:49:09 +00:00
|
|
|
|
2017-09-27 03:16:26 +00:00
|
|
|
$this->connection->table('password_resets')->insert([
|
2017-06-25 00:49:09 +00:00
|
|
|
'email' => $email,
|
|
|
|
'token' => $this->hasher->make($token),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $token;
|
|
|
|
}
|
|
|
|
}
|