<?php

namespace KupShop\WarehouseBundle\Util;

use KupShop\KupShopBundle\Util\System\PathFinder;
use Query\Operator;

class PasswordProvider
{
    /**
     * @var PathFinder
     */
    private $pathFinder;

    public function __construct(PathFinder $pathFinder)
    {
        $this->pathFinder = $pathFinder;
    }

    /**
     * @return bool|string
     */
    public function getLoginPassword($adminId)
    {
        $admin = sqlQueryBuilder()
            ->select('*')
            ->from('admins')
            ->where(Operator::equals(['id' => $adminId]))
            ->execute()
            ->fetch();

        return $this->hashPassword($admin['password']);
    }

    /**
     * @return bool|string
     */
    public function hashPassword($password)
    {
        return substr(md5($password), 0, 15);
    }
}
