mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-03 23:24:07 +01:00
* [ADD] Security enhancement for master password in session. * [MOD] Minor UI tweaks. * [MOD] Improved config handling. * [MOD] Code cleaning. * [FIX] Accounts' main group were not set when the user hadn't enough privileges. * [FIX] Accounts restoration didn't restore the account's main group.
130 lines
3.8 KiB
PHP
130 lines
3.8 KiB
PHP
<?php
|
|
/**
|
|
* sysPass
|
|
*
|
|
* @author nuxsmin
|
|
* @link http://syspass.org
|
|
* @copyright 2012-2015 Rubén Domínguez nuxsmin@syspass.org
|
|
*
|
|
* This file is part of sysPass.
|
|
*
|
|
* sysPass is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* sysPass is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
namespace SP;
|
|
|
|
defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
|
|
|
|
/**
|
|
* Class UserPassRecover para la gestión de recuperaciones de claves de usuarios
|
|
*
|
|
* @package SP
|
|
*/
|
|
class UserPassRecover
|
|
{
|
|
/**
|
|
* Tiempo máximo para recuperar la clave
|
|
*/
|
|
const MAX_PASS_RECOVER_TIME = 3600;
|
|
/**
|
|
* Número de intentos máximos para recuperar la clave
|
|
*/
|
|
const MAX_PASS_RECOVER_LIMIT = 3;
|
|
const USER_LOGIN_EXIST = 1;
|
|
const USER_MAIL_EXIST = 2;
|
|
|
|
/**
|
|
* Comprobar el hash de recuperación de clave.
|
|
*
|
|
* @param string $hash con el hash de recuperación
|
|
* @return int con el Id del usuario
|
|
*/
|
|
public static function checkHashPassRecover($hash)
|
|
{
|
|
$query = 'SELECT userpassr_userId FROM usrPassRecover '
|
|
. 'WHERE userpassr_hash = :hash '
|
|
. 'AND userpassr_used = 0 '
|
|
. 'AND userpassr_date >= :date '
|
|
. 'ORDER BY userpassr_date DESC LIMIT 1';
|
|
|
|
$data['hash'] = $hash;
|
|
$data['date'] = time() - self::MAX_PASS_RECOVER_TIME;
|
|
|
|
$queryRes = DB::getResults($query, __FUNCTION__, $data);
|
|
|
|
if ($queryRes === false) {
|
|
return false;
|
|
}
|
|
|
|
return $queryRes->userpassr_userId;
|
|
}
|
|
|
|
/**
|
|
* Marcar como usado el hash de recuperación de clave.
|
|
*
|
|
* @param string $hash con el hash de recuperación
|
|
* @return bool
|
|
*/
|
|
public static function updateHashPassRecover($hash)
|
|
{
|
|
$query = 'UPDATE usrPassRecover SET userpassr_used = 1 WHERE userpassr_hash = :hash';
|
|
|
|
$data['hash'] = $hash;
|
|
|
|
return DB::getQuery($query, __FUNCTION__, $data);
|
|
}
|
|
|
|
/**
|
|
* Comprobar el límite de recuperaciones de clave.
|
|
*
|
|
* @param string $login con el login del usuario
|
|
* @return bool
|
|
*/
|
|
public static function checkPassRecoverLimit($login)
|
|
{
|
|
$query = 'SELECT userpassr_userId ' .
|
|
'FROM usrPassRecover ' .
|
|
'WHERE userpassr_userId = :id ' .
|
|
'AND userpassr_used = 0 ' .
|
|
'AND userpassr_date >= :date';
|
|
|
|
$data['id'] = UserUtil::getUserIdByLogin($login);
|
|
$data['date'] = time() - self::MAX_PASS_RECOVER_TIME;
|
|
|
|
return (DB::getQuery($query, __FUNCTION__, $data) === false || DB::$lastNumRows >= self::MAX_PASS_RECOVER_LIMIT);
|
|
}
|
|
|
|
/**
|
|
* Insertar un registro de recuperación de clave.
|
|
*
|
|
* @param string $login con el login del usuario
|
|
* @param string $hash con el hash para el cambio
|
|
* @return bool
|
|
*/
|
|
public static function addPassRecover($login, $hash)
|
|
{
|
|
$query = 'INSERT INTO usrPassRecover SET '
|
|
. 'userpassr_userId = :userId,'
|
|
. 'userpassr_hash = :hash,'
|
|
. 'userpassr_date = UNIX_TIMESTAMP(),'
|
|
. 'userpassr_used = 0';
|
|
|
|
$data['userId'] = UserUtil::getUserIdByLogin($login);
|
|
$data['hash'] = $hash;
|
|
|
|
return DB::getQuery($query, __FUNCTION__, $data);
|
|
}
|
|
|
|
} |