0
1
Fork 0
hedera-web-mindshore/rest/core/recover-password.php

74 lines
1.7 KiB
PHP
Raw Normal View History

2016-09-06 14:25:02 +00:00
<?php
use Vn\Web;
2016-09-06 14:25:02 +00:00
class RecoverPassword extends Vn\Web\JsonRequest
{
const PARAMS = ['recoverUser'];
2016-09-06 14:25:02 +00:00
function run ($db)
{
$user = $db->getRow (
'SELECT c.`e-mail` mail, u.active
FROM vn2008.Clientes c
JOIN account.user u ON u.id = c.Id_Cliente
WHERE u.name = #',
[$_REQUEST['recoverUser']]
);
if (!($user['active'] && $user['mail']))
return TRUE;
$service = $this->service;
$token = $service->createToken ($_REQUEST['recoverUser'], FALSE, TRUE);
$url = $service->getUrl () ."#!form=account/conf&token=$token";
$report = new Vn\Web\Report ($db, 'recover-password', ['url' => $url]);
$report->sendMail ($user['mail']);
return TRUE;
}
2016-09-06 14:25:02 +00:00
const LOWERS = 'abcdefghijklmnopqrstuvwxyz';
const UPPERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const DIGITS = '1234567890';
const SYMBOLS = '!$%&()=.';
function genPassword ($db)
2016-09-06 14:25:02 +00:00
{
$restrictions = $db->getRow (
2016-09-23 22:47:34 +00:00
'SELECT length, nUpper, nDigits, nPunct FROM account.userPassword');
2016-09-06 14:25:02 +00:00
$pass = [];
$newPass = '';
$nAlpha = $restrictions['length'] - (
2016-09-23 22:47:34 +00:00
$restrictions['nUpper'] +
$restrictions['nDigits'] +
$restrictions['nPunct']);
2016-09-06 14:25:02 +00:00
$this->genRands ($pass, self::LOWERS, $nAlpha);
2016-09-23 22:47:34 +00:00
$this->genRands ($pass, self::UPPERS, $restrictions['nUpper']);
$this->genRands ($pass, self::DIGITS, $restrictions['nDigits']);
$this->genRands ($pass, self::SYMBOLS, $restrictions['nPunct']);
2016-09-06 14:25:02 +00:00
for ($i = count ($pass) - 1; $i >= 0; $i--)
{
$rand = rand (0, $i);
$newPass .= $pass[$rand];
array_splice ($pass, $rand, 1);
}
return $newPass;
2016-09-06 14:25:02 +00:00
}
function genRands (&$pass, $chars, $max)
{
$len = strlen ($chars) - 1;
for ($i = 0; $i < $max; $i++)
$pass[] = $chars[rand (0, $len)];
}
}