PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 25 → Wx - Trabalhando com dois bancos de dados  e com criptografia dos dados
Wx - Trabalhando com dois bancos de dados e com criptografia dos dados
Débuté par adrianoboller, 09 mar. 2016 00:13 - Aucune réponse
Membre enregistré
3 659 messages
Popularité : +175 (223 votes)
Posté le 09 mars 2016 - 00:13
Prezados,

Segue aqui um exemplo trabalhando com 2 bancos e com criptografia dos dados, a tabela também deve ter senha.

glosenha IS string =Crypt("ABACAXI", "LIMAO" ,cryptSecure+cryptAnsi,encodeBASE64)


Procedure ConectarDatabase()

ok is boolean

IF Upper(gsConfigProvider) = "MYSQL" OR gsConfigProvider = "" THEN

ConnMysql..Provider = hNativeAccessMySQL
ConnMysql..User = gsConfig_user
ConnMysql..Password = gsConfig_pw
ConnMysql..Server = gsConfig_ip
ConnMysql..Database = gsConfig_database
ConnMysql..Access = hOReadWrite

ok = HChangeConnection("*",ConnMysql)

ok = HOpenConnection(ConnMysql)

ELSE ConnMysql..Provider = hAccessHF7 //classic 7

ok = HCreationIfNotFound("*")

//ConnMysql..Provider = hAccessHFClientServer //server

END

bExiste is boolean = Ping(gsConfig_ip,1000)

IF bExiste = True AND ok = True

IF ok = True THEN

// Busca is data source //
// ok = HExecuteSQLQuery(Busca,hQueryDefault,"select * from wisetech_config")
// For each Busca //
// info (Busca.Titulo) //
// END //

ToastDisplay("Conectou com a base",toastShort,vaMiddle,haCenter,RGB(208, 249, 247))

ELSE

ToastDisplay("ERRO! Favor configurar o sistema para acesso ao DB!" + CR + "Entre em Contato com Claudio Quadros (41) 8844-6060" + CR + "comercial@wisetechti.com.br" + CR + "www.wisetechti.com.br",toastShort,vaTop,haCenter,RGB(250, 179, 179))

END

ELSE

Info("IP nao localizado!")

END

RESULT bExiste



Procedure AbrirSistema()

bAbriu is boolean = False

gnPosicaoJanela = WIN_LoginInicial..X

IF LerConfig() = True THEN //hiperfile

IF ConectarDatabase() = True THEN // mysql

WIN_LoginInicial..X = -2000 bAbriu = True

Open(WIN_Sistema)

ELSE

WIN_LoginInicial..X = gnPosicaoJanela

END

ELSE

Info("Nªo foi localizada a configuraªo")

WIN_LoginInicial..X = gnPosicaoJanela

END

RESULT bAbriu



Procedure GravarConfig()

ok is boolean = False

IF EDT_T001_database <> "" AND EDT_T001_ip <> "" AND EDT_T001_user <> "" THEN

ok = HChangeConnection("*",ConnHfsql) // hiperfile

ok = HDeleteAll(T001_config)

ok = HExecuteQuery(QRY_Insert_ConfigConexao, hCheckIntegrity+hCheckDuplicates+hQueryDefault,DateSys()+TimeSys(), Crypt(EDT_T001_ip, glosenha,cryptSecure+cryptAnsi,encodeBASE64), Crypt(EDT_T001_database,glosenha,cryptSecure+cryptAnsi,encodeBASE64), Crypt(EDT_T001_user, glosenha,cryptSecure+cryptAnsi,encodeBASE64),Crypt(EDT_T001_pw,glosenha,cryptSecure+cryptAnsi,encodeBASE64),Crypt(EDT_T001_provider, glosenha,cryptSecure+cryptAnsi,encodeBASE64))

//ok is boolean = HExecuteQuery(QRY_Insert_ConfigConexao, //hCheckIntegrity+hCheckDuplicates+hQueryDefault,datesys()+Timesys(),
//EDT_T001_ip, EDT_T001_database, EDT_T001_user,
//EDT_T001_pw,EDT_T001_provider)

IF ok = True THEN

ToastDisplay("Sucesso!",toastShort,vaTop,haCenter)

END

END

RESULT ok



Procedure LerConfig()

ok, registro is boolean = False

gsConfig_ip = ""

gsConfig_database = ""

gsConfig_user = ""

gsConfig_pw = ""

gsConfigProvider = ""

ok = HChangeConnection("*",ConnHfsql) //hiperfile

ok = HExecuteQuery(QRY_Select_ConfigConexao,hQueryDefault)

IF ok = True THEN

for each QRY_Select_ConfigConexao

registro = HFound(QRY_Select_ConfigConexao)

IF registro = True
EDT_T001_ip = Uncrypt(QRY_Select_ConfigConexao.t001_ip,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

EDT_T001_database = Uncrypt(QRY_Select_ConfigConexao.t001_database,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

EDT_T001_user = Uncrypt(QRY_Select_ConfigConexao.t001_user,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

EDT_T001_pw = Uncrypt(QRY_Select_ConfigConexao.t001_pw,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

EDT_T001_provider = Uncrypt(QRY_Select_ConfigConexao.t001_provider,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfig_ip = Uncrypt(QRY_Select_ConfigConexao.t001_ip,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfig_database = Uncrypt(QRY_Select_ConfigConexao.t001_database,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfig_user = Uncrypt(QRY_Select_ConfigConexao.t001_user,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfig_pw = Uncrypt(QRY_Select_ConfigConexao.t001_pw,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfigProvider = Uncrypt(QRY_Select_ConfigConexao.t001_provider,glosenha,cryptSecure+cryptAnsi,encodeBASE64)


// gsConfig_ip = QRY_Select_ConfigConexao.t001_ip
// gsConfig_database = QRY_Select_ConfigConexao.t001_database
// gsConfig_user = QRY_Select_ConfigConexao.t001_user
// gsConfig_pw = QRY_Select_ConfigConexao.t001_pw
// gsConfigProvider = QRY_Select_ConfigConexao.t001_provider


END

END

END

RESULT registro



Procedure Verifica()

bRegistros, achou is boolean = False

ok is boolean = HExecuteQuery(QRY_Select_ConfigConexao,hQueryDefault)

IF ok = True THEN

FOR EACH QRY_Select_ConfigConexao

bRegistros = HFound(QRY_Select_ConfigConexao)

IF bRegistros = True THEN

achou = True

EDT_T001_ip = Uncrypt(QRY_Select_ConfigConexao.t001_ip, glosenha, cryptSecure+cryptAnsi,encodeBASE64)

EDT_T001_database = Uncrypt(QRY_Select_ConfigConexao.t001_database,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

EDT_T001_user = Uncrypt(QRY_Select_ConfigConexao.t001_user,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

EDT_T001_pw = Uncrypt(QRY_Select_ConfigConexao.t001_pw,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

EDT_T001_provider = Uncrypt(QRY_Select_ConfigConexao.t001_provider,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfig_ip = Uncrypt(QRY_Select_ConfigConexao.t001_ip,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfig_database = Uncrypt(QRY_Select_ConfigConexao.t001_database,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfig_user = Uncrypt(QRY_Select_ConfigConexao.t001_user,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfig_pw = Uncrypt(QRY_Select_ConfigConexao.t001_pw,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

gsConfigProvider = Uncrypt(QRY_Select_ConfigConexao.t001_provider,glosenha,cryptSecure+cryptAnsi,encodeBASE64)

END

END

END

IF achou = True THEN
AbrirSistema()
END


Bons estudos e sempre procurem complicar o acesso aos dados da conexão criptografando em tabelas que so podem ser abertas pela aplicação. Assim evita que outros entrem no banco de Dados e Drop o mesmo.

Grandes Poderes... Grandes Responsabilidades...

Forte abraço a todos....

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.blogspot.com.br/