diff --git a/inc/SP/Auth/Database/Database.class.php b/inc/SP/Auth/Database/Database.class.php index b6d7d15a..483e8321 100644 --- a/inc/SP/Auth/Database/Database.class.php +++ b/inc/SP/Auth/Database/Database.class.php @@ -109,7 +109,6 @@ class Database implements AuthInterface return $queryRes !== false && $Data->getQueryNumRows() === 1 - && (Hash::checkHashKey($this->UserData->getUserPass(), $queryRes->getUserPass()) - || hash_equals($queryRes->getUserPass(), crypt($this->UserData->getUserPass(), $queryRes->getUserHashSalt()))); + && Hash::checkHashKey($this->UserData->getUserPass(), $queryRes->getUserPass()); } } \ No newline at end of file diff --git a/inc/SP/Core/Installer.class.php b/inc/SP/Core/Installer.class.php index 507eb6d0..20c28b5e 100644 --- a/inc/SP/Core/Installer.class.php +++ b/inc/SP/Core/Installer.class.php @@ -366,13 +366,15 @@ class Installer $this->DB->exec('DROP USER `' . $this->InstallData->getDbUser() . '`@`' . $this->InstallData->getDbAuthHost() . '`'); $this->DB->exec('DROP USER `' . $this->InstallData->getDbUser() . '`@`' . $this->InstallData->getDbAuthHostDns() . '`'); $this->DB->exec('DROP USER `' . $this->InstallData->getDbUser() . '`@`%`'); + + debugLog('Rollback'); + + return true; } catch (PDOException $e) { debugLog($e->getMessage()); return false; } - - return true; } /** @@ -391,8 +393,8 @@ class Installer __('No es posible crear la BBDD de la aplicación. Descárguela de nuevo.', false)); } - // Usar la base de datos de sysPass try { + // Usar la base de datos de sysPass $this->DB->exec('USE `' . $this->InstallData->getDbName() . '`'); } catch (PDOException $e) { throw new SPException(SPException::SP_CRITICAL, @@ -447,59 +449,43 @@ class Installer */ private function createAdminAccount() { - $GroupData = new GroupData(); - $GroupData->setUsergroupName('Admins'); - $GroupData->setUsergroupDescription('sysPass Admins'); - try { + $GroupData = new GroupData(); + $GroupData->setUsergroupName('Admins'); + $GroupData->setUsergroupDescription('sysPass Admins'); + Group::getItem($GroupData)->add(); - } catch (SPException $e) { - $this->rollback(); - throw new SPException(SPException::SP_CRITICAL, - __('Error al crear el grupo "admin"', false), - __('Informe al desarrollador', false)); - } - $ProfileData = new ProfileData(); - $ProfileData->setUserprofileName('Admin'); + $ProfileData = new ProfileData(); + $ProfileData->setUserprofileName('Admin'); - try { Profile::getItem($ProfileData)->add(); - } catch (SPException $e) { - $this->rollback(); - throw new SPException(SPException::SP_CRITICAL, - __('Error al crear el perfil "admin"', false), - __('Informe al desarrollador', false)); - } - // Datos del usuario - $UserData = new UserData(); - $UserData->setUserGroupId($GroupData->getUsergroupId()); - $UserData->setUserProfileId($ProfileData->getUserprofileId()); - $UserData->setUserLogin($this->InstallData->getAdminLogin()); - $UserData->setUserPass($this->InstallData->getAdminPass()); - $UserData->setUserName('Admin'); - $UserData->setUserIsAdminApp(1); + // Datos del usuario + $UserData = new UserData(); + $UserData->setUserGroupId($GroupData->getUsergroupId()); + $UserData->setUserProfileId($ProfileData->getUserprofileId()); + $UserData->setUserLogin($this->InstallData->getAdminLogin()); + $UserData->setUserPass($this->InstallData->getAdminPass()); + $UserData->setUserName('Admin'); + $UserData->setUserIsAdminApp(1); - try { User::getItem($UserData)->add(); - } catch (SPException $e) { + + // Guardar el hash de la clave maestra + ConfigDB::setCacheConfigValue('masterPwd', Hash::hashKey($this->InstallData->getMasterPassword())); + ConfigDB::setCacheConfigValue('lastupdatempass', time()); + ConfigDB::writeConfig(true); + + if (!UserPass::getItem($UserData)->updateUserMPass($this->InstallData->getMasterPassword())) { + throw new SPException(SPException::SP_CRITICAL, + __('Error al actualizar la clave maestra del usuario "admin"', false), + __('Informe al desarrollador', false)); + } + } catch (\Exception $e) { $this->rollback(); throw new SPException(SPException::SP_CRITICAL, - __('Error al crear el usuario "admin"', false), - __('Informe al desarrollador', false)); - } - - // Guardar el hash de la clave maestra - ConfigDB::setCacheConfigValue('masterPwd', Hash::hashKey($this->InstallData->getMasterPassword())); - ConfigDB::setCacheConfigValue('lastupdatempass', time()); - ConfigDB::writeConfig(true); - - if (!UserPass::getItem($UserData)->updateUserMPass($this->InstallData->getMasterPassword())) { - $this->rollback(); - - throw new SPException(SPException::SP_CRITICAL, - __('Error al actualizar la clave maestra del usuario "admin"', false), + $e->getMessage(), __('Informe al desarrollador', false)); } }