Im having this function to determine weather a user exists in a database or not
DM is my DataModule
AQ_LOGIN an ADOQuery
BENU is my Table filled with Users and their Password
Here comes the code:
function UserCheckExist(Login, pw: string): boolean;
begin
with DM do
begin
AQ_LOGIN.Close;
AQ_LOGIN.SQL.Clear;
AQ_LOGIN.SQL.Add('select BLOGIN from BENU where BLOGIN = ''Login'' AND BPW = ''pw''');
AQ_LOGIN.Open;
end;
end;
My question now is: How can I make the function return true or false weather the User with the according password exists?
Thanks in advance.
I'd go with smok1's answer (I was just posting something like it) but I'd parameterise your inputs, thus;
AQ_LOGIN.SQL.Add('select count(*) from BENU where BLOGIN=:login and BPW=:pw');
AQ_LOGIN.Parameters.ParamByName('login').AsString:=login;
AQ_LOGIN.Parameters.ParamByName('pw').AsString:=pw;
then as with smok1 - open the dataset and look at the value of the returned count.
NB - don't have an ADO delphi component handy but 99.9% sure that's the syntax :-)
edit: one of the advantages of using parameters like this is that you won't have to sanitise your input strings (for things like quotes) - the component knows what to do with your strings. You wouldn't expect to have a username with a single quote in it, but you might have a password with one. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With