1
I’m having a hard time logging in Delphi
with encrypted password at the bank MySQL
, I can do the registration
and encrypt the password in the database through Delphi
with the StoredProcedure
that I created at MySQL
, this encryption I did through the function MD5
of the own MySQL
. In the Delphi
, use TSQLStoredProc
to use the StoredProcedure
of the database.
The difficulty is in Function
that I created at Mysql
, it returns an integer. If zero
the return:
o login está incorreto
If it is um
:
o login está certo
To Function
works properly on MySQL
, makes the correct comparison, however, what I do not know is how to show or compare this Function
with this whole return in the Delphi
.
Here’s my code so you’ll understand:
SQL:
DELIMITER $$
CREATE TABLE `tbl_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(15) NOT NULL,
`firstlast_name` varchar(80) DEFAULT NULL,
`password` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
)$$
DELIMITER ;
DELIMITER $$
DROP FUNCTION IF EXISTS `fun_valida_usuario`$$
CREATE FUNCTION `fun_valida_usuario`(p_username VARCHAR(15)
, p_password VARCHAR(45) ) RETURNS INT(1)
BEGIN
DECLARE _ret INT(1) DEFAULT 0;
SET _ret = IFNULL((SELECT DISTINCT 1
FROM tbl_users
WHERE `username` = p_username
AND `password` = MD5(p_password)),0);
RETURN _ret;
END$$
DELIMITER ;
DELIMITER $$
CREATE PROCEDURE `proc_iae_tbl_users`(
p_opc varchar(1),
p_id int,
p_username varchar(15),
p_firstlast_name varchar(80),
p_password varchar(45))
BEGIN
IF ((p_opc = 'I') && (p_username != '') && (p_password != '')) THEN
INSERT INTO tbl_users (id, username, firstlast_name, `password`) VALUES (p_id, p_username, p_firstlast_name, MD5(p_password));
ELSE
IF ((p_opc = 'E') && (p_id > 0)) THEN
delete from tbl_users where id = p_id;
ELSE
IF ((p_opc = 'A')) THEN
UPDATE tbl_users set id = p_id, username = p_username, firstlast_name = p_firstlast_name, `password` = p_password WHERE id = p_id;
ELSE
SELECT 'Você não pode realizar as alterações' AS Msg;
END IF;
END IF;
END IF;
END$$
DELIMITER ;
PAS:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WideStrings, DBXMySql, DB, SqlExpr, FMTBcd, Provider, DBClient,
StdCtrls, Mask, DBCtrls;
type
TForm1 = class(TForm)
SQLConnection1: TSQLConnection;
ClientDataSet1: TClientDataSet;
DataSetProvider1: TDataSetProvider;
SQLQuery1: TSQLQuery;
SQLQuery1id: TIntegerField;
SQLQuery1username: TStringField;
SQLQuery1firstlast_name: TStringField;
SQLQuery1password: TStringField;
DataSource1: TDataSource;
ClientDataSet1id: TIntegerField;
ClientDataSet1username: TStringField;
ClientDataSet1firstlast_name: TStringField;
ClientDataSet1password: TStringField;
InsertUser: TButton;
Edit1: TEdit;
Edit2: TEdit;
proc_iae_tbl_users: TSQLStoredProc;
proc_iae_tbl_usersMsg: TStringField;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
VerifyLogin: TButton;
Label1: TLabel;
Label2: TLabel;
SQLStoredProc1: TSQLStoredProc;
SQLStoredProc1Value: TIntegerField;
Label3: TLabel;
DBEdit1: TDBEdit;
DataSource2: TDataSource;
SQLQuery2: TSQLQuery;
SQLQuery2Valor: TIntegerField;
Label4: TLabel;
DBEdit2: TDBEdit;
DataSource3: TDataSource;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.InsertUserClick(Sender: TObject);
begin
proc_iae_tbl_users.Close;
proc_iae_tbl_users.ParamByName('p_opc').Value:= 'I';
proc_iae_tbl_users.ParamByName('p_username').Value:= Edit1.Text;
proc_iae_tbl_users.ParamByName('p_firstlast_name').Value:= Edit2.Text;
proc_iae_tbl_users.ParamByName('p_password').Value:= Edit3.Text;
proc_iae_tbl_users.ExecProc;
end;
procedure TForm1.VerifyLoginClick(Sender: TObject);
begin
// Aqui deve ficar o código para logar e verificar o login
end;
end.
Someone can give me a solution?
I appreciate your willingness from the start. Thank you.
Wow, that makes a lot of sense. I’m going to start addressing them. While Tstoredproc, I used only to perform the CRUD, because I have a process in the bank for this. And to log in, I used Tsqlquery, because I have to pass an SQL and this SQL has to be the user Tedit and password. If you have how to do with Tstoredproc I don’t know :/ Thanks for the help.
– WilliamCanin