<?php
#   SGT - The SGT for Internet - http://sgt.eti.br
#   Copyright (c) 2016-2018, Jean Azevedo. All rights reserved.

#   This file is part of SGT.

#   SGT 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
#   any later version.

#   SGT 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
    echo '<p>Iniciando Atualização do Banco de Dados!</p>';
    include "conectar.php";
    require "criptografia_sgt.php";
    include "chave_sgt.php";
    $buscar = $pdo_sgt->query("SELECT * FROM tb_usuarios ORDER BY usuario");
    if($buscar->rowCount() > 0){
        while($ver = $buscar->fetch(PDO::FETCH_ASSOC)){ 
            $senha = $ver['senha'].$userpasssgt;
            $query=$pdo_sgt->prepare("UPDATE tb_usuarios SET senha=:senha WHERE id=:id");
            $query->bindValue(":senha",$senha);
            $query->bindValue(":id",$ver['id']);
            $query->execute();
        }
    }
    echo '<p>Senhas dos Usuários Atualizadas!</p>';
    $buscar = $pdo_sgt->query("SELECT * FROM tb_key");
    if($buscar->rowCount() > 0){
        while($ver = $buscar->fetch(PDO::FETCH_ASSOC)){ 
            $senha = $ver['senha'];
            $sgt_cript = new SGT_KEY();
            $sgt_cript -> chave = $chave_num;
            $sgt_cript -> add_text = md5(sha1($chave_txt));
            $key_crip = $sgt_cript -> bloq($senha);
            $query=$pdo_sgt->prepare("UPDATE tb_key SET senha=:senha WHERE id=:id");
            $query->bindValue(":senha",$key_crip);
            $query->bindValue(":id",$ver['id']);
            $query->execute();
        }
    }
    echo '<p>Senhas Atualizadas!</p>'  
        .'<a href="index.php">OK</a>';
?>