Sign in to follow this  
Followers 0
FMS

Compare whit decrypted array goes wrong.

11 posts in this topic

#1 ·  Posted (edited)

Hello,

I'm having trouble whit a scipt what I'm building where this is a snippit from, and hope somebody can help me whit.
The problem lies in when i push the "add" button i want to check if the "user" already exists.
But the search code i build founds 2 hits when i know there is only 1 hit.

does somebody knows what I'm doing wrong?

thanks in advance.

Ps. if somebody knows " if i found the right user how can i rewrite the password for him/her? " an answer to that will be most appriciated :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#Include <Timers.au3>
#include <Crypt.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Pie", 170, 235, 190, 200)
local $usernames[0]
local $passwords[0]

global $selectuser = GUICtrlCreateCombo("", 21, 95, 130, 20)
$addusername = GUICtrlCreateButton("Add", 21, 170, 130, 30)
$usernamefield = GUICtrlCreateInput("", 21, 120, 130, 20)
$passwordfield = GUICtrlCreateInput("", 21, 145, 130, 20, 0x0020)

func encrypt()
    Local $hFileOpen = FileOpen("data.srmt",  $FO_APPEND)

    if guictrlread($usernamefield) <> "" then
;~   local $encryptedusername = string(guictrlread($usernamefield))
;~   local $encryptedpassword = string(guictrlread($passwordfield))
      local $encryptedusername = string(_Crypt_EncryptData(guictrlread($usernamefield), "P14h735536jk3fvvbg", $CALG_AES_128))
      local $encryptedpassword = string(_Crypt_EncryptData(guictrlread($passwordfield ), "P14h735536jk3fvvbg", $CALG_AES_128))
      Local $iCheck_hit = False
      ConsoleWrite (@CRLF & "##############################################"& @CRLF)
      if ubound($usernames)> 0 then
         for $i = 0 to ubound($usernames)-1
            If  guictrlread($usernamefield) = $usernames[$i] Then
               $iCheck_hit = True
               ConsoleWrite ( "Found! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF)
;~          Else
;~             ConsoleWrite ( "No! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF)
            EndIf
         next
      EndIf
      ConsoleWrite ( "##############################################"& @CRLF)
      If $iCheck_hit = False Then
         FileWrite($hFileOpen, $encryptedusername & @CRLF)
         FileWrite($hFileOpen, $encryptedpassword & @CRLF)
      EndIf
    EndIf

    FileClose($hFileOpen)
EndFunc

func decrypt()
    Local $hFileOpen = FileOpen("data.srmt", $FO_READ)

;~     consolewrite(_FileCountLines("data.srmt") & " lines in the file" & @CRLF)

    for $i = 1 to _FileCountLines("data.srmt")/2
        local $encryptedusername = FileReadLine($hFileOpen)
        local $encryptedpassword = FileReadLine($hFileOpen)

;~         consolewrite($encryptedusername  & @CRLF)
;~         consolewrite($encryptedpassword  & @CRLF)

;~         _ArrayAdd($usernames, FileReadLine($hFileOpen))
;~         _ArrayAdd($passwords, FileReadLine($hFileOpen))

        _ArrayAdd($usernames, binarytostring(_Crypt_DecryptData(binary($encryptedusername), "P14h735536jk3fvvbg", $CALG_AES_128)))
        _ArrayAdd($passwords, binarytostring(_Crypt_DecryptData(binary($encryptedpassword), "P14h735536jk3fvvbg", $CALG_AES_128)))
    Next

    FileClose($hFileOpen)

;~     consolewrite(ubound($usernames) & " entries in array")
;~     _arraydisplay($usernames)

    if ubound($userNames)> 0 then
        for $i = 0 to ubound($usernames)-1
            GUICtrlSetData($selectuser, $usernames[$i])
        next
    EndIf
endfunc

func updatecomboandinfo()
   if not GUICtrlRead($usernamefield) = "" Then
      _ArrayAdd($usernames, GUICtrlRead($usernamefield))
      _ArrayAdd($passwords, GUICtrlRead($passwordfield))

      GUICtrlSetData($selectuser, $usernames[UBound($usernames)-1])

   EndIf
EndFunc

decrypt()

GUISetState(@SW_SHOW)
While True
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $addusername
         updatecomboandinfo()
         encrypt()
         GUICtrlSetData($usernamefield, "")
         GUICtrlSetData($passwordfield, "")
      Case $selectuser
         if ubound($usernames)> 0 then
            for $i = 0 to ubound($usernames)-1
;~                      msg( "error",$array_decrypted_usernames[$i])
               If $usernames[$i] = GUICtrlRead($selectuser) Then
                  GUICtrlSetData($usernamefield, $usernames[$i])
                  GUICtrlSetData($passwordfield, $passwords[$i])
                  consolewrite("YES " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF)
               Else
;~                         msg( "error",$array_decrypted_usernames[$i])
                  consolewrite("NO " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF)
               EndIf
            next
         EndIf
   EndSwitch
WEnd

 

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites



I can't find a wrong CrLf, this time i see no error:

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
YES 0 = test | ctr = test
NO 1 = test2 | ctr = test
NO 0 = test | ctr = test2
YES 1 = test2 | ctr = test2

what's the issue you have?

Share this post


Link to post
Share on other sites

lol, no this time "there is no crlf" :) , thanks for that ;)
But this time is when i try for the second time "add" the same username.
(this i want to check in encrypt function(between the ####### lines)
and when i found a name that is already there i want to change only the old $password whit the new one.(whis is a question on his own:)
but this script found it 2 times :S and don't know where the second time comes from :)


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

ok understand, i will have a look on it tomorrow morning. But may be a look on LoginCheck2.au3 and PasswortCreator2.au3 gives you a better idea (=> use INI file). Both are for a loginsystem. Only commeted in german but i hope code is good enough for speacking for himself understanding.

Share this post


Link to post
Share on other sites

thanks @AutoBert,
because this is a snippit i used username & pssword :) just to be a little bit simpler to understand.
these array's arn't realy login checks but in real life a group right set function.
--> iff user X has right Y($password) he might use a function or not.
This way i don't rely on a AD system or what so ever :) and normal users cant dig around in the files the program uses to change anything on there own.


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

I think i got some clue found :)
but can't figure out what exactly or how to overcom it.
I think it's in the function updatecomboandinfo.
When you select a previous filled in username it also add it into the array.
I'm working on it now how to do this :)

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

After som fideling around i get this snippet working :)
Dont know iff I'm on the right track (it's working now but maybe there is still a bug inside:S)
Now that i found the right $password could somebody tell me how to rewrite it?
Did some digging around but din't find anythin usefull.
 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#Include <Timers.au3>
#include <Crypt.au3>
#include <GuiEdit.au3>
#Include <GuiComboBoxEx.au3>
$Form1 = GUICreate("Pie", 170, 235, 190, 200)


global $selectuser = GUICtrlCreateCombo("", 21, 95, 130, 20)
$addusername = GUICtrlCreateButton("Add", 21, 170, 130, 30)
$usernamefield = GUICtrlCreateInput("", 21, 120, 130, 20)
$passwordfield = GUICtrlCreateInput("", 21, 145, 130, 20, 0x0020)

func encrypt()
    Local $hFileOpen = FileOpen("data.srmt",  $FO_APPEND)

    if guictrlread($usernamefield) <> "" then
      local $encryptedusername = string(_Crypt_EncryptData(guictrlread($usernamefield), "P14h735536jk3fvvbg", $CALG_AES_128))
      local $encryptedpassword = string(_Crypt_EncryptData(guictrlread($passwordfield ), "P14h735536jk3fvvbg", $CALG_AES_128))
      Local $iCheck_hit = False
      ConsoleWrite (@CRLF & "##############################################"& @CRLF)
      if ubound($usernames)> 0 then
         for $i = 0 to ubound($usernames)-1
            If  guictrlread($usernamefield) = $usernames[$i] Then
               $iCheck_hit = True
               ConsoleWrite ( "Found! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF)
;~          Else
;~             ConsoleWrite ( "No! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF)
            EndIf
         next
      EndIf
      ConsoleWrite ( "##############################################"& @CRLF)
      If $iCheck_hit = False Then
         FileWrite($hFileOpen, $encryptedusername & @CRLF)
         FileWrite($hFileOpen, $encryptedpassword & @CRLF)
      EndIf
    EndIf

    FileClose($hFileOpen)
    decrypt()
EndFunc

func decrypt()
   
   _GUICtrlComboBoxEx_ResetContent(GUICtrlGetHandle($selectuser))
   Global $usernames[0]
   Global $passwords[0]

   Local $hFileOpen = FileOpen("data.srmt", $FO_READ)

   Local $j = 0
    for $i = 1 to _FileCountLines("data.srmt")/2

        local $encryptedusername = FileReadLine($hFileOpen)
        local $encryptedpassword = FileReadLine($hFileOpen)
        
        _ArrayAdd($usernames, binarytostring(_Crypt_DecryptData(binary($encryptedusername), "P14h735536jk3fvvbg", $CALG_AES_128)))
        _ArrayAdd($passwords, binarytostring(_Crypt_DecryptData(binary($encryptedpassword), "P14h735536jk3fvvbg", $CALG_AES_128)))
        ConsoleWrite ($j & " = j ####"& $usernames[$j] & @CRLF)
        GUICtrlSetData($selectuser, $usernames[$j])
        $j = $j + 1
    Next

    FileClose($hFileOpen)
endfunc

decrypt()

GUISetState(@SW_SHOW)
While True
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $addusername
         encrypt()
         GUICtrlSetData($usernamefield, "")
         GUICtrlSetData($passwordfield, "")
      Case $selectuser
         if ubound($usernames)> 0 then
            for $i = 0 to ubound($usernames)-1
               If $usernames[$i] = GUICtrlRead($selectuser) Then
                  GUICtrlSetData($usernamefield, $usernames[$i])
                  GUICtrlSetData($passwordfield, $passwords[$i])
;~                _GUICtrlComboBox_SetCurSel($usernamefield,$i)
                  consolewrite("YES " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF)
               Else
                  consolewrite("NO " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF)
               EndIf
            next
         EndIf
   EndSwitch
WEnd

 

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
1 hour ago, FMS said:

Now that i found the right $password could somebody tell me how to rewrite it?

 

i added a func for the rewriting:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#Include <Timers.au3>
#include <Crypt.au3>
#include <GuiEdit.au3>
#Include <GuiComboBoxEx.au3>
$Form1 = GUICreate("Pie", 170, 235, 190, 200)


Global $usernames
global $selectuser = GUICtrlCreateCombo("", 21, 95, 130, 20)
$addusername = GUICtrlCreateButton("Add", 21, 170, 130, 30)
$usernamefield = GUICtrlCreateInput("", 21, 120, 130, 20)
$passwordfield = GUICtrlCreateInput("", 21, 145, 130, 20, 0x0020)

func encrypt()
    Local $hFileOpen = FileOpen("data.srmt",  $FO_APPEND)

    if guictrlread($usernamefield) <> "" then
      local $encryptedusername = string(_Crypt_EncryptData(guictrlread($usernamefield), "P14h735536jk3fvvbg", $CALG_AES_128))
      local $encryptedpassword = string(_Crypt_EncryptData(guictrlread($passwordfield ), "P14h735536jk3fvvbg", $CALG_AES_128))
      Local $iCheck_hit = False
      ConsoleWrite (@CRLF & "##############################################"& @CRLF)
      if ubound($usernames)> 0 then
         for $i = 0 to ubound($usernames)-1
            If  guictrlread($usernamefield) = $usernames[$i] Then
               $iCheck_hit = True
               ConsoleWrite ( "Found! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF)
               ExitLoop ;needed for knowing which pwd maybe changed
               ;otherwise the _ReplacePWDinFile must search agian for it. 
;~          Else
;~             ConsoleWrite ( "No! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF)
            EndIf
         next
      EndIf
      ConsoleWrite ( "##############################################"& @CRLF)
      If $iCheck_hit = False Then
         FileWrite($hFileOpen, $encryptedusername & @CRLF)
         FileWrite($hFileOpen, $encryptedpassword & @CRLF)
      Else
         _ReplacePWDinFile($encryptedusername,$encryptedpassword,($i+1)*2)
      EndIf
    EndIf

    FileClose($hFileOpen)
    decrypt()
EndFunc

func decrypt()

   _GUICtrlComboBoxEx_ResetContent(GUICtrlGetHandle($selectuser))
   Global $usernames[0]
   Global $passwords[0]

   Local $hFileOpen = FileOpen("data.srmt", $FO_READ)

   Local $j = 0
    for $i = 1 to _FileCountLines("data.srmt")/2

        local $encryptedusername = FileReadLine($hFileOpen)
        local $encryptedpassword = FileReadLine($hFileOpen)

        _ArrayAdd($usernames, binarytostring(_Crypt_DecryptData(binary($encryptedusername), "P14h735536jk3fvvbg", $CALG_AES_128)))
        _ArrayAdd($passwords, binarytostring(_Crypt_DecryptData(binary($encryptedpassword), "P14h735536jk3fvvbg", $CALG_AES_128)))
        ConsoleWrite ($j & " = j ####"& $usernames[$j] & @CRLF)
        GUICtrlSetData($selectuser, $usernames[$j])
        $j = $j + 1
    Next

    FileClose($hFileOpen)
endfunc

decrypt()

GUISetState(@SW_SHOW)
While True
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $addusername
         encrypt()
         GUICtrlSetData($usernamefield, "")
         GUICtrlSetData($passwordfield, "")
      Case $selectuser
         if ubound($usernames)> 0 then
            for $i = 0 to ubound($usernames)-1
               If $usernames[$i] = GUICtrlRead($selectuser) Then
                  GUICtrlSetData($usernamefield, $usernames[$i])
                  GUICtrlSetData($passwordfield, $passwords[$i])
;~                _GUICtrlComboBox_SetCurSel($usernamefield,$i)
                  consolewrite("YES " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF)
               Else
                  consolewrite("NO " & $i & " = " &  $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF)
               EndIf
            next
         EndIf
   EndSwitch
WEnd

Func _ReplacePWDinFile($sUser,$sPWD,$iLine)
    Local $sFilepath="data.srmt"
;   For $i=1 To _FileCountLines($sFilepath) Step 2
;       If $sUser=FileReadLine($sFilepath,$i) Then
;           ConsoleWrite('_ReplacePWDinFile Found: '&$sUser&@TAB&$i&@CRLF)
;           ExitLoop
;       EndIf
;   Next
;   Local $iLine=$i+1
    _FileWriteToLine($sFilepath,$iLine,$sPWD,True)
    ConsoleWrite('_ReplacePWDinFile _FileWriteToLine '&$iLine&': '&@error&' '&@extended&@CRLF)
EndFunc

 

Share this post


Link to post
Share on other sites

THNX!!! @AutoBert this totaly solved the problem :)

2 points for grifindor!


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

You noticed that _FileWriteToLine don't work with Filehandle? I suggest further to declare the filepath once as a const and use it in every func needing the filepath: 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <Timers.au3>
#include <Crypt.au3>
#include <GuiEdit.au3>
#include <GuiComboBoxEx.au3>
$Form1 = GUICreate("Pie", 170, 235, 190, 200)
ConsoleWrite(@OSVersion & @CRLF)

Global Const $sFilepath = "data.srmt"

Global $usernames
Global $selectuser = GUICtrlCreateCombo("", 21, 95, 130, 20)
$addusername = GUICtrlCreateButton("Add", 21, 170, 130, 30)
$usernamefield = GUICtrlCreateInput("", 21, 120, 130, 20)
$passwordfield = GUICtrlCreateInput("", 21, 145, 130, 20, 0x0020)

Func encrypt()
    Local $hFileOpen = FileOpen($sFilepath, $FO_APPEND)

    If GUICtrlRead($usernamefield) <> "" Then
        Local $encryptedusername = String(_Crypt_EncryptData(GUICtrlRead($usernamefield), "P14h735536jk3fvvbg", $CALG_AES_128))
        Local $encryptedpassword = String(_Crypt_EncryptData(GUICtrlRead($passwordfield), "P14h735536jk3fvvbg", $CALG_AES_128))
        Local $iCheck_hit = False
        ConsoleWrite(@CRLF & "##############################################" & @CRLF)
        If UBound($usernames) > 0 Then
            For $i = 0 To UBound($usernames) - 1
                If GUICtrlRead($usernamefield) = $usernames[$i] Then
                    $iCheck_hit = True
                    ConsoleWrite("Found! " & @CRLF & $usernames[$i] & " = " & GUICtrlRead($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF)
                    ExitLoop ;needed for knowing which pwd maybe changed
                    ;otherwise the _ReplacePWDinFile must search agian for it.
;~          Else
;~             ConsoleWrite ( "No! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF)
                EndIf
            Next
        EndIf
        ConsoleWrite("##############################################" & @CRLF)
        If $iCheck_hit = False Then
            FileWrite($hFileOpen, $encryptedusername & @CRLF)
            FileWrite($hFileOpen, $encryptedpassword & @CRLF)
        Else
            _ReplacePWDinFile($encryptedusername, $encryptedpassword, ($i + 1) * 2)
        EndIf
    EndIf

    FileClose($hFileOpen)
    decrypt()
EndFunc   ;==>encrypt

Func decrypt()

    _GUICtrlComboBoxEx_ResetContent(GUICtrlGetHandle($selectuser))
    Global $usernames[0]
    Global $passwords[0]

    Local $hFileOpen = FileOpen($sFilepath, $FO_READ)

    Local $j = 0
    For $i = 1 To _FileCountLines($sFilepath) / 2

        Local $encryptedusername = FileReadLine($hFileOpen)
        Local $encryptedpassword = FileReadLine($hFileOpen)

        _ArrayAdd($usernames, BinaryToString(_Crypt_DecryptData(Binary($encryptedusername), "P14h735536jk3fvvbg", $CALG_AES_128)))
        _ArrayAdd($passwords, BinaryToString(_Crypt_DecryptData(Binary($encryptedpassword), "P14h735536jk3fvvbg", $CALG_AES_128)))
        ConsoleWrite($j & " = j ####" & $usernames[$j] & @CRLF)
        GUICtrlSetData($selectuser, $usernames[$j])
        $j = $j + 1
    Next

    FileClose($hFileOpen)
EndFunc   ;==>decrypt

decrypt()

GUISetState(@SW_SHOW)
While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $addusername
            encrypt()
            GUICtrlSetData($usernamefield, "")
            GUICtrlSetData($passwordfield, "")
        Case $selectuser
            If UBound($usernames) > 0 Then
                For $i = 0 To UBound($usernames) - 1
                    If $usernames[$i] = GUICtrlRead($selectuser) Then
                        GUICtrlSetData($usernamefield, $usernames[$i])
                        GUICtrlSetData($passwordfield, $passwords[$i])
;~                _GUICtrlComboBox_SetCurSel($usernamefield,$i)
                        ConsoleWrite("YES " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF)
                    Else
                        ConsoleWrite("NO " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF)
                    EndIf
                Next
            EndIf
    EndSwitch
WEnd

Func _ReplacePWDinFile($sUser, $sPWD, $iLine)
    ;   For $i=1 To _FileCountLines($sFilepath) Step 2
    ;       If $sUser=FileReadLine($sFilepath,$i) Then
    ;           ConsoleWrite('_ReplacePWDinFile Found: '&$sUser&@TAB&$i&@CRLF)
    ;           ExitLoop
    ;       EndIf
    ;   Next
    ;   Local $iLine=$i+1
    _FileWriteToLine($sFilepath, $iLine, $sPWD, True)
    ConsoleWrite('_ReplacePWDinFile _FileWriteToLine ' & $iLine & ': ' & @error & ' ' & @extended & @CRLF)
EndFunc   ;==>_ReplacePWDinFile

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I noticed it,
I'm comparing it now whit what I just got finished.
It is deleting the file and combo en rebuilding everythin.
(this snippit come's from mine project so the $ aren't the same)
What do you tink of this work flow? (Isn't this way asking more resources instead of your way?)

edit: filewrite whit new $encrypted_username_false
 

func encrypt_rights()
   FileDelete($GL_file_rigths_location);------------------------------------------------------------------------------------backup function?
   Local $hFileOpen = FileOpen($GL_file_rigths_location,  $FO_APPEND)

   if guictrlread($input_username) <> "" then
      local $encrypted_username = string(_Crypt_EncryptData(guictrlread($input_username), $GL_encr_key, $CALG_AES_128))
      local $encrypted_rights = string(_Crypt_EncryptData(guictrlread($combo_right ), $GL_encr_key, $CALG_AES_128))
      Local $iCheck_hit = False
;~    ConsoleWrite (@CRLF & "##############################################"& @CRLF)
      if ubound($array_decrypted_usernames)> 0 then
         for $i = 0 to ubound($array_decrypted_usernames)-1
            If  guictrlread($input_username) = $array_decrypted_usernames[$i] Then
               $iCheck_hit = True
               ConsoleWrite ( "Found! "& @CRLF & $array_decrypted_usernames[$i] & " = " & guictrlread($input_username) & @CRLF & "i = " & $i & @CRLF & @CRLF)
               FileWrite($hFileOpen, $encrypted_username & @CRLF)
               FileWrite($hFileOpen, $encrypted_rights & @CRLF)
            Else
               Local $encrypted_username_false = string(_Crypt_EncryptData($array_decrypted_usernames[$i], $GL_encr_key, $CALG_AES_128))
               Local $encrypted_rights_false = string(_Crypt_EncryptData($array_decrypted_rights[$i], $GL_encr_key, $CALG_AES_128))
               FileWrite($hFileOpen, $encrypted_username_false & @CRLF)
               FileWrite($hFileOpen, $encrypted_rights_false & @CRLF)
            EndIf
         next
      EndIf
;~    ConsoleWrite ( "##############################################"& @CRLF)
      If $iCheck_hit = False Then
         FileWrite($hFileOpen, $encrypted_username & @CRLF)
         FileWrite($hFileOpen, $encrypted_rights & @CRLF)
      EndIf
   EndIf

   FileClose($hFileOpen)
   decrypt_rights()
EndFunc

func decrypt_rights($switch = False)
   Global $array_decrypted_usernames[0]
   Global $array_decrypted_rights[0]

   If $switch = "start" Then
      Local $hFileOpen = FileOpen($GL_file_rigths_location, $FO_READ)
      for $i = 1 to _FileCountLines($GL_file_rigths_location)/2
         local $encrypted_username = FileReadLine($hFileOpen)
         local $encrypted_rights = FileReadLine($hFileOpen)
         _ArrayAdd($array_decrypted_usernames, binarytostring(_Crypt_DecryptData(binary($encrypted_username), $GL_encr_key, $CALG_AES_128)))
         _ArrayAdd($array_decrypted_rights, binarytostring(_Crypt_DecryptData(binary($encrypted_rights), $GL_encr_key, $CALG_AES_128)))
      Next
      FileClose($hFileOpen)
   Else
      _GUICtrlComboBoxEx_ResetContent(GUICtrlGetHandle($combo_usr_select))
      Local $hFileOpen = FileOpen($GL_file_rigths_location, $FO_READ)

      Local $j = 0
      for $i = 1 to _FileCountLines($GL_file_rigths_location)/2
         local $encrypted_username = FileReadLine($hFileOpen)
         local $encrypted_rights = FileReadLine($hFileOpen)
         _ArrayAdd($array_decrypted_usernames, binarytostring(_Crypt_DecryptData(binary($encrypted_username), $GL_encr_key, $CALG_AES_128)))
         _ArrayAdd($array_decrypted_rights, binarytostring(_Crypt_DecryptData(binary($encrypted_rights), $GL_encr_key, $CALG_AES_128)))
         ConsoleWrite ($j & " = j ####"& $array_decrypted_usernames[$j] & @CRLF)
         GUICtrlSetData($combo_usr_select, $array_decrypted_usernames[$j])
         $j = $j + 1
      Next

      FileClose($hFileOpen)
   EndIf
endfunc

 

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • czardas
      By czardas
      Haven't had much time to code recently. However the following thread inspired me.
      The debate about linear, parallel and binary search methods was rather interesting and, in an attempt to be diplomatic, I decided to combine @jchd's suggestion with @LarsJ's binary search example. I decided that the binary search algorithm required modification to make it more linear. As usual, 'if you invent something, it probably already exists and if it already exists, it exists for a reason'. My first attempt was not all that good. The code worked but was really a mess. I blame peer pressure (to post an example of a parallel search method).  I will delete that old code in due course.
      With a little memory jogging and a glance at the help file, the solution turned out to be quite easy: I just needed a better understanding of Euler. Further modification will be needed to work with more complicated unicode strings. The output could be returned as an array or a delimitered string. I'm not so interested in those details. I'm just going to post the algorithm for now and anyone, who wants to, can modify it to suit their needs. Both arrays must contain at least 1 element.
      Local $aFoo = [0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,19,20,23,24,26,30,35,39,40,41] Local $aBar = [0,1,5,6,7,8,9,10,11,12,13,14,17,18,19,21,24,25,26,27,34,35,38,40] ParallelExponetialSearch($aFoo, $aBar) ; Compares two lists - returning positive matches. Each input array must be unique (individually) and in alphabetical order. Func ParallelExponetialSearch($aFoo, $aBar) Local $sFind, _ $iMin_F = -1, $iMax_F = UBound($aFoo) -1, $Lo_F = $iMin_F, $Hi_F, _ $iMin_B = -1, $iMax_B = UBound($aBar) -1, $Lo_B = $iMin_B, $Hi_B While $iMin_F < $iMax_F And $iMin_B < $iMax_B ; Toggle Arrays - Which array has most untested elements? This is the one we want to search next, ; so we can bypass more comparisons because (in theory) mismatches have a greater chance of being skipped. If $iMax_F - $iMin_F >= $iMax_B - $iMin_B Then ; $aFoo has more (or an equal number of) untested elements $Hi_F = $iMax_F $iMin_B += 1 $sFind = $aBar[$iMin_B] While $Lo_F < $Hi_F ; search $aFoo For $i = 0 To Floor(Log($Hi_F - $Lo_F) / Log(2)) $Lo_F = $iMin_F + 2^$i If $aFoo[$Lo_F] = $sFind Then $iMin_F = $Lo_F ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $Lo_F & "] = $aBar[" & $iMin_B & "]" & @LF) ExitLoop 2 ElseIf $aFoo[$Lo_F] > $sFind Then $Hi_F = $Lo_F -1 $iMin_F += Floor(2^($i -1)) $Lo_F = $iMin_F ContinueLoop 2 EndIf Next $iMin_F = $Lo_F ; minimum increment is one WEnd Else ; $aBar has more untested elements $Hi_B = $iMax_B $iMin_F += 1 $sFind = $aFoo[$iMin_F] While $Lo_B < $Hi_B ; search $aBar For $i = 0 To Floor(Log($Hi_B - $Lo_B) / Log(2)) $Lo_B = $iMin_B + 2^$i If $aBar[$Lo_B] = $sFind Then $iMin_B = $Lo_B ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $iMin_F & "] = $aBar[" & $Lo_B & "]" & @LF) ExitLoop 2 ElseIf $aBar[$Lo_B] > $sFind Then $Hi_B = $Lo_B -1 $iMin_B += Floor(2^($i -1)) $Lo_B = $iMin_B ContinueLoop 2 EndIf Next $iMin_B = $Lo_B ; minimum increment is one WEnd EndIf WEnd EndFunc ;==> ParallelExponetialSearch I hope this will be useful to someone. I believe it deserved a thread of its own!
    • ur
      By ur
      We can get a list of file using the below code.
      Local $aFileList = _FileListToArray(@DesktopDir, "*") Is there any option to use the above one recursively to get sub folders and their contents also.??
      And also, is there any way to serialize the above array locally to some file and load it later when we want in another program on another machine so that we can compare its contents with a folder in different machine, which is not network connected also.?
    • ur
      By ur
      Generally we will use tools like Winmerge or Beyond Compare for this purpose.
      Are there any UDF or libraries available in AutoIT to compare any two files or folder contents.
    • FMS
      By FMS
      Hello,
      I think this is a simple question if you know the answer.
      At this function i try to  (encrypt -> decrypt -> change -> encrypt ->decrypt->check ) an array.
      This is a snippet from a larger script but the error is the same.
      I do this encrypt decrypt action so i can save some setting along the way in a file.
      But at the end (when i change the data and not when i dont change the data) is empty.
      does somebody see what i'm doing wrong here?
       
      Func test() Local $LC_timestamp = @MDAY & "." & @MON & "." & @YEAR & "_" & @HOUR & ":" & @MIN & ":" & @SEC Global $GL_USS_base_count = 4 Global $GL_USS_base[$GL_USS_base_count][2] = [["nickname", "FMS"], ["last_login", $LC_timestamp], ["login_count", "1" ], ["naam3", $LC_timestamp]] Global $encrypted_GL_USS_true[$GL_USS_base_count] Global $encrypted_GL_USS_content_true[$GL_USS_base_count] Global $GL_array_decrypted_USS_names[$GL_USS_base_count] Global $GL_array_decrypted_USS_settings[$GL_USS_base_count] MsgBox($MB_SYSTEMMODAL, "should be 1", $GL_USS_base[2][1]) ;make for $i = 0 to $GL_USS_base_count -1 $encrypted_GL_USS_true[$i] = _Crypt_EncryptData($GL_USS_base[$i][0], $GL_encr_key_settings, $CALG_AES_128) $encrypted_GL_USS_content_true[$i] = _Crypt_EncryptData($GL_USS_base[$i][1], $GL_encr_key_settings, $CALG_AES_128) Next ;get for $i = 0 to $GL_USS_base_count -1 $GL_array_decrypted_USS_names[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) $GL_array_decrypted_USS_settings[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_content_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) Next MsgBox($MB_SYSTEMMODAL, "should be 1", $GL_array_decrypted_USS_settings[2]) ;change $GL_array_decrypted_USS_settings[2] = $GL_array_decrypted_USS_settings[2] + "1" MsgBox($MB_SYSTEMMODAL, "should be 2", $GL_array_decrypted_USS_settings[2]) ;save for $i = 0 to $GL_USS_base_count -1 $encrypted_GL_USS_true[$i] = _Crypt_EncryptData($GL_array_decrypted_USS_names[$i], $GL_encr_key_settings, $CALG_AES_128) $encrypted_GL_USS_content_true[$i] = _Crypt_EncryptData($GL_array_decrypted_USS_settings[$i], $GL_encr_key_settings, $CALG_AES_128) Next ;get for $i = 0 to $GL_USS_base_count -1 $GL_array_decrypted_USS_names[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) $GL_array_decrypted_USS_settings[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_content_true[$i]), $GL_encr_key_settings, $CALG_AES_128)) Next ;check MsgBox($MB_SYSTEMMODAL, "should be 2", $GL_array_decrypted_USS_settings[2]) ;why is this emty????? EndFunc thanks in advanced
    • cherrylatte
      By cherrylatte
      hi 
      I'm trying to make a script that runs different functions depending on the local time of the computer
      I tried to do
      if _NowCalcDate < 2016/04/12 Then
       functionA()
      Else
       functionB()
      Endif
       
      and that doesn't seem to work.
      I am assuming that value returned from _NowCalcDate doesn't match with the date type I wrote
       
      What should I do? I'd appreciate for any help that's given.