-
Password Problem
Hi
I am creating a username and password log in system and at the moment i am having problems.
what i want at the moment is when you put in the password it will come up in the labe "OK" just so that i know it is working.
here is the code i have at the moment
Code:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char Password;
char guess;
if (guess = Password)
{
lbOutput->Caption = "ok";
}
can anyone help?
Thanks
-
So, you have two uninitialized char variables (guess and password). You then assign guess to password, and check if it's non-zero, and set the caption to "ok".
This all seems wrong to me.
First of all, shouldn't password and guess be something that comes from the outside (e.g. parts of the form)? And I'm almost certain they should be strings rather than single chars...
And you should COMPARE the guess with password, rather than assign it...
--
Mats
-
Code:
#include <string.h>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char Password[256]; //need enough char's to fit the password + 1
char guess[256];
//now fill the Password from the source / database / ect
//get the users input into 'guess'
//from the Password edit on Form1
//compare char arrays ( == will not work )
if( strcmp ( guess, Password) == 0) //are same
{
lbOutput->Caption = "ok";
}
-
update of the full code if it will help
Code:
void __fastcall TForm2::lbOutputClick(TObject *Sender)
{
char password[256];
Application->MessageBox("Incorrect Password, Please Try again",
"Error - Incorrect Password",MB_ICONWARNING);
edPassword->Clear();
password = edPassword->Text;
if ( edPassword == "administrator")
{
Form2->Close();
Form1->Show();
}
else
lbOutput->Visible = true;
lbOutput->Caption = "Incorrect Password";
}
-
Shouldn't this
if ( edPassword == "administrator")//you are using the EDIT control
be
if ( password == "administrator")//should be using the char array (text)
but you can not (usually) do a string compare without using a class (CString or string)
try
if ( strcmp(password, "administrator") == 0 )//match, include <string.h>
-
i have change some of the items to what you have said but i believe the problem may be
Code:
password = edPassword->Text;
but i am unsure how to fix this because it comes up with the error .
-
sorted it i think - thanks :)