Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datamodule and Sql Query

Status
Not open for further replies.

Rached

Programmer
Mar 30, 2003
54
DK
Hello all, we are building a database application, but don't know to check for a user password from the table. here is my code,
this is the login form, i populate the combobox with availabe recods from the database

void __fastcall Tlogin::FormActivate(TObject *Sender)
{
datamodule1->Query1->SQL->Clear();
datamodule1->Query1->SQL->Add("SELECT * FROM User");
datamodule1->Query1->Open();

ComboBox1->Items->Add(datamodule1->Query1->FieldByName("UserName")->AsString);
while (datamodule1->Query1->FindNext())
{
ComboBox1->Items->Add(datamodule1->Query1->FieldByName("UserName")->AsString);
}

}

the user chooses a user name, we only have two in the table and will not use more, one with full permissions, and the other with partail use of the program. When the user chooses a user, types in password in the edit box, and press ok

void __fastcall Tlogin::OKClick(TObject *Sender)
{
datamodule1->Query1->SQL->Clear();
datamodule1->Query1->SQL->Add("SELECT * FROM User");
datamodule1->Query1->Open();

if ((ComboBox1->Text == "Manager") && (login->Edit1->Text == datamodule1->Query1->FieldByName("UserPassword")->AsString))
{
ComboBox1->Text =="Manager";
login->Hide();
mainmenu->ShowModal();
}
else if ((ComboBox1->Text == "Assistant") && (login->Edit1->Text == datamodule1->Query1->FieldByName("UserPassword")->AsString))
{
login->Hide();
mainmenu->Image7->Hide();
mainmenu->Button6->Hide();
mainmenu->Button7->Hide();
mainmenu->Button2->Hide();
mainmenu->Label1->Hide();
mainmenu->Label7->Hide();
mainmenu->Label6->Hide();
mainmenu->Label5->Hide();
mainmenu->ShowModal();
}
}

how to take all the passowrds from the tables, and match the user name with the password? coz in our code, it only takes the first password from the table which is the manager's password.

plx help, tnx guys
 
I do not know wich database you are using, but if your database has users and passwords you automatically get a screen for the user and the password . I mostly use sybase (but it is the same for other databases) and when i make the query active i get a prompt for user and password.

Wim Vanherp
Wim.Vanherp@belgacom.net
 
I dont think this is his intended usage. I think he is using a table to store the usernames and passwords for access to his app. I personally would use TTable instead
of the TQuery and try to match the password input to the password on the table that corresponds to the selected user.

if (Edit1->Text == Table1->Fieldvalue [password])
do something.

you could use strcmp ();

please dont quote this code verbatim. :)

I do think I could try to use this process in the future of the TQuery as I can see that it could be useful.

tomcruz.net
 
thank you guys, actually butthead is right; i am using one table to store users names and teir passes and depending on their entry i give access to the special forms of the application. i am using ms access db; but butthead ure line was useful. tnx :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top