misc_pterodactyl-panel/app/Services/Helpers/TemporaryPasswordService.php

60 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2017-09-26 02:43:01 +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
*/
namespace Pterodactyl\Services\Helpers;
2018-03-05 04:42:33 +00:00
use Ramsey\Uuid\Uuid;
use Illuminate\Contracts\Hashing\Hasher;
2017-09-27 03:16:26 +00:00
use Illuminate\Database\ConnectionInterface;
class TemporaryPasswordService
{
const HMAC_ALGO = 'sha256';
/**
2017-09-27 03:16:26 +00:00
* @var \Illuminate\Database\ConnectionInterface
*/
2017-09-27 03:16:26 +00:00
protected $connection;
/**
* @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
*/
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;
$this->hasher = $hasher;
}
/**
* Store a password reset token for a specific email address.
*
2017-08-22 03:10:48 +00:00
* @param string $email
* @return string
*/
2017-09-27 03:16:26 +00:00
public function handle($email)
{
2018-03-05 04:42:33 +00:00
$token = hash_hmac(self::HMAC_ALGO, Uuid::uuid4()->toString(), config('app.key'));
2017-09-27 03:16:26 +00:00
$this->connection->table('password_resets')->insert([
'email' => $email,
'token' => $this->hasher->make($token),
]);
return $token;
}
}