Page 25 of 40

Posted: Wed Oct 24, 2007 4:57 pm
by AL90
gnozal wrote:So it seems to be a ZLIB issue ?
this is possible. Unfortunately, I also can say nothing to it.
I have no more ideas how you can fix it. :cry:

check if the user password is correct

Posted: Thu Nov 01, 2007 6:45 pm
by Micko
hi gnozal
i would like to check if the user password is correct before extract zip files

Code: Select all

MyZIP.s = "C:\Test.zip"
MyZIPFile1.s = "C:\Compressor Xpert.exe"
MyZIPFile2.s = "C:\French.lng"
MyZIPFile3.s = "C:\English.lng"
MyZIPOutPut.s = "C:\TempZip"
If PureZIP_Archive_Create(MyZIP.s, #APPEND_STATUS_CREATE)
   PureZIP_SetArchivePassword("azerty")
   PureZIP_Archive_Compress(MyZIPFile1.s, #False)
   PureZIP_Archive_Compress(MyZIPFile2.s, #False)
   PureZIP_Archive_Compress(MyZIPFile3.s, #False)
   PureZIP_Archive_Close()
EndIf
MessageRequester("Info","Success",0)

; i need to check if the password is correct before unzip files
; but i can't make it work !
Input.s = InputRequester("Zip is crypted", "Password:", "")
If PureZIP_Archive_Read(MyZIP.s)
  If Input
     If PureZIP_SetArchivePassword(Input)
         ReturnValue.l = PureZIP_Archive_FindFirst() = #UNZ_OK
        While ReturnValue = #UNZ_OK
         PureZIP_Archive_Extract(MyZIPOutPut.s, #True)
         ReturnValue = PureZIP_Archive_FindNext()
        Wend:MessageRequester("Info","Files are extracted !",0)
       Else: MessageRequester("Info","Error !",0):EndIf
    Else:MessageRequester("Info","please input password !",0):EndIf
 PureZIP_Archive_Close()
EndIf

Re: check if the user password is correct

Posted: Mon Nov 05, 2007 10:15 am
by gnozal
Micko wrote:hi gnozal
i would like to check if the user password is correct before extract zip files
You can't.
The password isn't stored in the archive.
If the password is wrong, you get an error during decompression.

Posted: Mon Nov 05, 2007 12:42 pm
by Micko
thanks gnozal

Posted: Mon Nov 05, 2007 10:47 pm
by Micko
pleaz gnozal can you explain me how the password is stored and test before extraction ?

Posted: Mon Nov 05, 2007 11:30 pm
by DoubleDutch
For security reasons I don't think that zip files store that kind of information, I think you only know that a password is incorrect when you get errors during the uncompression.

Posted: Tue Nov 06, 2007 8:58 am
by gnozal
DoubleDutch wrote:For security reasons I don't think that zip files store that kind of information, I think you only know that a password is incorrect when you get errors during the uncompression.
Exactly.

Posted: Tue Nov 06, 2007 10:12 am
by DoubleDutch
Micko: If what you want to do is find the password to a zip file, then you can find this IF one of the files is a known file. A known file is an original file before it was zipped.

That is why you should NEVER make password protected zips with files where some of the files are available unzipped. This would render the password protection virtually useless because it make it possible to reverse the process to find the original password for the encypted files.

See http://www.lostpassword.com/zip.htm and look at the section on "Known plaintext".

Posted: Tue Nov 06, 2007 3:22 pm
by Micko
thanks DoubleDutch for these informations :)

know i try to extract files that are password protected and check if there is errors during the uncompression ?
here is the result i have
files are always extracted with size(0) , if the password is incorrect :shock:

Code: Select all

SourceDir .s = "Test.Zip" ;protected with password
Chemin.s = "C:\Temp"
While Valeur_Retour = #UNZ_OK
              myFileinfo.PureZIP_FileInfo
              ExtractValue = PureZIP_ExtractFiles(SourceDir, "*.*", Chemin, #True)
               If ExtractValue  = #Null : Goto MessageError
               Else
              Valeur_Retour = PureZIP_Archive_FindNext() 
              EndIf
 Wend
MessageError :       
              MessageRequester("Error","Incorrect password, can't process files !",#MB_ICONWARNING)
what i need is to avoid files extraction until the password is incorrect

Posted: Tue Nov 06, 2007 4:14 pm
by gnozal
The decompression is done after the file has been created, so you have a zero file.
You can avoid it like this :

Code: Select all

If PureZIP_Archive_Read("c:\test.zip")
  IsOk = PureZIP_Archive_FindFirst()
  While IsOk = #Z_OK
    If IsOk = PureZIP_Archive_Extract("c:\", #False)
      Debug "Ok"
    Else
      Debug "Extraction problem"
      PureZIP_Archive_FileInfo(@FileInfo.PureZIP_FileInfo)
      If FileSize("c:\" + FileInfo\FileName) = 0
        Debug "Zero length = deleting"
        DeleteFile("c:\" + FileInfo\FileName)
      EndIf
    EndIf
    IsOk = PureZIP_Archive_FindNext()
  Wend
  PureZIP_Archive_Close()
EndIf

Posted: Tue Nov 06, 2007 4:38 pm
by Micko
thank you very much gnozal :D

Posted: Wed Nov 07, 2007 8:11 pm
by Micko
gnozal i'm working with your last code but it seems to work when the total files in zip not Exceed 10 else i get this message "Extraction problem", but couldn't delete files.

Posted: Thu Nov 08, 2007 8:53 am
by gnozal
Micko wrote:gnozal i'm working with your last code but it seems to work when the total files in zip not Exceed 10 else i get this message "Extraction problem", but couldn't delete files.
?!
I just tested the code with a crypted archive containing 28 files : no problem (all zero length files deleted).

If you can assume the password is the same for all files, this code may suffice : it quits after the first failure.

Code: Select all

If PureZIP_Archive_Read("c:\test.zip") 
  IsOk = PureZIP_Archive_FindFirst() 
  While IsOk = #Z_OK 
    If IsOk = PureZIP_Archive_Extract("c:", #False) 
      Debug "Ok" 
    Else 
      PureZIP_Archive_FileInfo(@FileInfo.PureZIP_FileInfo) 
      Debug "Extraction problem for " + FileInfo\FileName
      If FileSize("c:" + FileInfo\FileName) = 0 
        Debug "Zero length = deleting " + FileInfo\FileName
        DeleteFile("c:" + FileInfo\FileName)
        Debug "And exiting .."
        Break
      EndIf 
    EndIf 
    IsOk = PureZIP_Archive_FindNext() 
  Wend 
  PureZIP_Archive_Close() 
EndIf
Just a thought : if you have read-only files, of course it won't work : you have to reset the read-only attribute before deleting.

Posted: Thu Nov 08, 2007 7:13 pm
by Micko
gnozal wrote:Just a thought : if you have read-only files, of course it won't work : you have to reset the read-only attribute before deleting.
oh yes ! i forgot :cry: sorry for took your times but this always help me :D
thanks a lot

Posted: Fri Nov 09, 2007 7:10 pm
by Micko

Code: Select all

If FileSize("c:\" + FileInfo\FileName) = 0 
this line never return 0 but -1 when i test. if i change 0 to -1 it works.
so i think it is Inexistants file(PB help). every day should be the same to me because i catch something in my mind. :)
thanks gnozal

Gnozal i want to set zip size to quad i process file to support file > 2Go
did i do it like this

Code: Select all

If PureZIP_Archive_Create(MyZIP.s, #APPEND_STATUS_CREATE)
Size.q = FileInfo\unCompressedSize & $FFFFFFFF
Size.q = filesize(MyZIPFile1.s)
 PureZIP_Archive_Compress(MyZIPFile1.s, #FALSE)
  PureZIP_Archive_Close()
EndIf