Hello Everyone,
My application is written under C#, but for some of the low level stuff I have to use C++ dll's and one of the dll require password before I can make some function call or if user entered wrong should ask again.....
How can I implement something along those lines....
At first I can send the pasword, but if the password is wrong what is the way to get the password....If you want I can even post my procedure which asks for password.....
Any help, suggestion highly appreciated...
Thanks,
Harsimrat

CallBack from a WIN 32 C++ dll
MHoess
Hello Jeff,
From my C# Program, at some point I run the Open_USB_Channel Function. At that point dll detects if the device is connected (Blackberry) if yes tries to open the Communication Channel and that point it needs device Password, C++ function gets callback from a function which is in the dll....
First time I can send the Password, hopefully no problem. If thats the correct pasword everything is fine....
The problem starts if thats the wrong password.....How can I ask user at that point enter the new Password.....The bigger problem is when I get a callback from the device I have no way of getting out of that loop....its a VIRTUAL method..... __stdcall......So what happens is it stays 10 times in that loop and wipes the device......thats the functionality that if you enter wrong password 10 times it wipes it.....
I can't find any way to go around it....If you want I can send you my code...no problem......but as if you have a BB will help you otherwise wont.......
Hopefully I have explianed myself.....If you need more explanation will try to give that if you need it.....
Thanks,
Harsimrat
kabalweg
Absolutely correct....
And even if you take out that do while loop still stays in there.......I dont know why....have no idea.....
virtual
HRESULT STDMETHODCALLTYPE raw_OnChallenge( /* [in] */ long attemptsRemaining, /* [out] */ unsigned char passwordHash[20] ){
attemptsRemaining;
char password[20]; int passwordMax = 14; int exit = 0; int theChar = 0; int numChars = 0; static int count = 0;sha_hash(password, strlen(password), passwordHash);
return S_OK;}
The code above once you go in, cant get out...I dont know why....There will be a solution but I dont know how....
Eric Q D
Sorry for confusing you.....
C#, program checks the device is connected, yes calls the comm channel......
A: send the password to the C++ dll and if that password is wrong the C++ function
gets caught in a loop.
Only returns if the password was correct or after 10 ten tries and wipes the device...At that point returns with COM Error as connection got unexpectedly closed.....
Balbiesas
Hmm, I'm rather confused, but I would really like to under stand this and try and help you out. Lets pseudo code this out first and make sure our logic is on the same page. I'll write out the steps that I think is going on and you fix my mistakes or add missing steps.
Ok, lets start with just the first steps, no code, just logic:
1. Your C# program sees if the the device is connected and opens the comm channel
2. Now, do you:
A: send the password to the C++ dll and if that password is wrong the C++ function
gets caught in a loop
-OR-
B: do you call the C++ function to get the password, and inside that function it gets
caught in a loop on the wrong password
PeterPanTech
What were to happen if you were to return something other than S_OK, like: E_UNEXPECTED or E_FAIL
Branimir Giurov
Questions:
1. You mean you can't get out of the do-while loop in the function above Or do you mean your program keeps calling the function above
2. You have this to put the password's char into the password var and then put '*' to the screen:
else if ( !theChar ) {
getch();
//
// legit character
// store it within the password, echo '*' to the screen
//
} else {
password[numChars++] = (char)theChar;
putch('*');
}
Shouldn't you remove the "else" and move it's code to the "else if( !theChar )", and remove the extra "getch()" like this:
else if ( !theChar ) {
//
// legit character
// store it within the password, echo '*' to the screen
//
password[numChars++] = (char)theChar;
putch('*');
}
Once again, I may just not be understanding you right, I put your code from above in to VS just so I could format it so I could try and understand it, and that is what I got from it. I hope I'm helping you and not anoying you with dumb questions, haha.
Rag2004_1
Ok, so the C# program is the one that asks for the password first, right
So, your problem is then, that if the the password is wrong, it doesn't get out of the C++ function and back to the C# to ask for the password again before the 10 tries are up, correct
otakung
tomahawk009
Jeremy_B
Ok, let me see if I have this,
1. Your C# program sees if the the device is connected and opens the comm channel
2. Then you need to send the password to the C++ dll
What exactly happens when the user enters the wrong password Does it send a message back to the C++ function that a wrong password has been entered If so, couldn't you just have the C++ function return a value that indicates whether or not the password was correct. Then place that C++ function in a loop in a C# program that will keep calling the C++ function until it gets the correct password.
That sounds too simple though, I probably am not understanding exactly what's going on. Please point out where I'm going wrong.
Ankaiah
The do while loop I just added, I was testing in C++ on the command line that if I can call the Password Function Properly...
From the C# code that wont be relevant any more....
Secondly, the program is calling the function again and again. After the sha_password call, if its the correct password it comes out, otherwise it just stays there asks, the code above works as the command line interface gets the new Password.
If I'm calling the same thing from C#, I dont know how to do that.......get the password again.......
I know I dont explain things very well, if you want more explanation let me know....
Thanks,
Harsimrat
GGiant
Absolutely correct..and the worst part is everytime you loop in, it thinks you entered the wrong password and even you are displaying the message box after 10 message boxes it will wipe the device....
I don't know how BlackBerry has created this functionality I have to somehow deal with it. If I would have known this before would have created my app in C++.....
Thanks, for the help.
Harsimrat
nun123
Hello Jeff,
When the dll calls the Password Check function....it doesnt return anything....once it goes into that loop, I cant find a way to get out of there......even i say exit or return no affect....this is how that functions like....
irtual HRESULT STDMETHODCALLTYPE raw_OnChallenge(
/* [in] */ long attemptsRemaining,
/* [out] */ unsigned char passwordHash[20] )
{
attemptsRemaining;
char password[20];
int passwordMax = 14;
int exit = 0;
int theChar = 0;
int numChars = 0;
static int count = 0;
printf( "Attempt %d of 10 to enter password.\n", ++count );
printf( "Note that the device will be wiped out after 10 failed attempts.\n\n" );
printf( "Enter BlackBerry password: " );
do
{
theChar = getch();
// // user hit Enter to exit // if ( theChar == 0x0D || theChar == 0x0A ){
++exit;
// // returns 0 if a function or cursor key has been hit // get next char to clear the scan code //}
else if ( !theChar ) {getch();
// // legit character // store it within the password, echo '*' to the screen //}
else {password[numChars++] = (
char)theChar;putch('*');
}
}
while ( !exit && numChars < passwordMax );password[numChars] = 0;
printf( "\n");
sha_hash(password, strlen(password), passwordHash);
return S_OK;}
I find no way to get out of this loop......
Any suggestions......
daveodolph
So if you were to do this:
virtual HRESULT STDMETHODCALLTYPE raw_OnChallenge(
/* [in] */ long attemptsRemaining, /* [out] */ unsigned char passwordHash[20] )
{
MessageBox( NULL, "BLAH", "", 0 );
return S_OK;}
then the "BLAH" MessagBox would get called 10 times