|
Post by Kevin on Mar 29, 2009 19:08:38 GMT -5
I would still do it from the OnBadPassword event...
var CurrentIndex := -1; PwdCount := 0;
procedure MainForm.OnBadPasswordEvent(Sender: TObject; FileIndex: Integer; var NewPassword: string); begin if (CurrentIndex = FileIndex) then begin Inc(PwdCount,1); // Keep track up to 3 times if (PwdCount > 3) then raise EUserCanceled.Create('Incorrect Password'); end else begin CurrentIndex := FileIndex; // New file PwdCount := 1; // 1st try for this file end; NewPassword := InputBox('Need Password', 'NewPassword:',''); end;
Your code that calls UnZip...
with frmMain.Zipper do begin ZipName := RestoreFilename; // set the zip filename RootDir := 'Settings'; FilesList.Add('*.*'); DestDir := TmpFolder; // Set destination directory DoAll := False; try Unzip; except On EUserCanceled do // do whatever you want here, if anything end;
end;
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Mar 30, 2009 4:07:18 GMT -5
At last you understood me I made as you wrote,but if just to press OK in the InputBox('Need Password' this try Unzip; except on EUserCanceled do begin // do whatever you want here, if anything Showmessage('Wrong password'); Exit; end; end; end; does not help I still see "I''m here" try Unzip; except on EUserCanceled do begin // do whatever you want here, if anything Showmessage('Wrong password'); Exit; end; end; end;
showmessage('I''m here');
|
|
|
Post by Kevin on Mar 30, 2009 8:26:55 GMT -5
You should not get to the InputBox in the OnBadPassword event if it is more than the third time. The code I wrote was just off the top of my head so there could be a little something wrong with it.
When you debug, are you getting to this code after the third try?
raise EUserCanceled.Create('Incorrect Password');
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Mar 30, 2009 15:46:07 GMT -5
Well, if I do not enter any pass and press OK I have to see "I'm here", if I enter wrong password 3-d time, I have to see "I'm here" too
|
|
|
Post by Kevin on Mar 30, 2009 16:07:39 GMT -5
But you did not answer my question. When you debug, in the OnBadPassword event, does the following line ever get executed?
raise EUserCanceled.Create('Incorrect Password');
If not, then the code to keep the proper count needs some tweaking. If that line of code is being executed and your "except" is not catching it then something is wrong and let me know about that.
Kevin
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Mar 30, 2009 16:26:21 GMT -5
I never got "Incorrect Password" message. Also I may be we should change if (PwdCount > 3) then to if (PwdCount > 2) then ? But this nothing changes
|
|
|
Post by Kevin on Mar 30, 2009 17:14:21 GMT -5
I just tested the code and it works just as I posted it with no changes. If I enter 3 incorrect passwords, the exception is raised and the "On EUserCanceled" code catches it. If you want to throw the exception when the user does not change the password or a blank password or whatever, you can check for that after the InputBox and add the raise EUserCanceled line there too.
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Mar 30, 2009 18:15:21 GMT -5
I ever used the same wrong test password ;D At last temppass:= InputBox('Need Password', 'NewPassword:',''); if (temppass='') or (temppass=NewPassword) then raise EUserCanceled.Create('Incorrect Password') else NewPassword:=temppass;
helped me. Thank you!
|
|
|
Post by Kevin on Mar 30, 2009 18:18:50 GMT -5
It works exactly as posted when I test it. If I change it to PwdCount > 1 then it will happen after the 1st incorrect attempt. I am not sure what your code looks like in all so I can't comment on why it is doing what it is doing for you.
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Mar 30, 2009 18:31:34 GMT -5
How should i define temppass? Utf8String/AnsiString or something else in D2009 ?
|
|
|
Post by Kevin on Mar 30, 2009 18:43:38 GMT -5
In D2009 that doesn't matter. You can define it as String or AnsiString (D2009 will make the conversion to AnsiString when putting it in NewPassword). But if you want to be able to have Unicode characters in your passwords, then define it as UTF8String and I believe D2009 will convert it automatically. Then the contents of the string will be UTF8 when you put it into NewPassword.
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on May 11, 2009 6:33:20 GMT -5
It does not work. Password, written in Russian, with "Current language for non unicode programs: English" does not work in windows with "Current language for non unicode programs: Russian" To store password I use usual "string" in D2009.
|
|
|
Post by Kevin on May 11, 2009 7:30:35 GMT -5
It does not work. What is the code that is not working? Are you saying that using a usual string in D2009 works correctly for you? Kevin
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on May 11, 2009 8:54:58 GMT -5
Code works, password does not work correct because of ansi.
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on May 11, 2009 9:05:26 GMT -5
russian word "пароль" saved by notepad into ansi text file with "Current language for non unicode programs: Russian" settings in windows , looks like "ïàðîëü" with "Current language for non unicode programs: English".
|
|