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

    • 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.
    • rc1986
      By rc1986
      Good morning,
      I currently have a little application that I have used the Crypt.au3 include to provide a basic form of encryption.  I have a little GUI which prompts the user to enter their passwords, this is then encrypted and written to a text file in its encrypted form.  When this user/password is required the code decrypts it and uses it on the fly.
      The way I am currently doing this is by using a passkey or master key withing the script itself to decrypt/encrypt.  This is the bit that concerns me as of course this isn't very secure.  Initially this didn't matter to me as what I'd created was much better than previous plain sight passwords in batch files etc however now I'd like to find a way of improving the security.
      Would anyone be able to offer any insight or other techniques/3rd party app integration etc to assist with my problem?
    • 09stephenb
      By 09stephenb
      How secure is:

      _Crypt_EncryptFile _Crypt_DecryptFile I understand the strength of encryption is mainly down to the algorithm and password, but I’m not referring to either of these, I am looking to find out how strong the code behind crypt it.

      I have noticed when encrypting a file, it uses a “.tmp” file while encrypting. In my experience a “.tmp” file is temporary and is deleted after use. But does this file contain any data that is related to the file being encrypted, or worse the password itself. Even though the file is deleted, it could possibly be recovered with a tool like: https://www.piriform.com/recuva.

      I'm not quite sure if this is a potential security threat, and if anyone could say if it is or not then that would be much appreciated.