Jump to content

[solved]Problems with encrypt/Decrypt


Recommended Posts

i jus realized that u are right, it is saving the username and password diffrently every time you encrypt it. which means the login isnt going to work right

sorry but i cant help you :unsure: if you get this working its going to be an awesome script though

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Link to comment
Share on other sites

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Yes you are right. But dunno why i got a feeling that the answer to this problem it's easy and i don't know were to search for it... or a clue or something.

I hope someone could help with this one

Link to comment
Share on other sites

Hello guys i have bin thinking for a while, searching the help file, searching the forum maybe i can find the asnwer on my on and after that i was thinking at the command inireadsection so what have i done.

- so i replace the code for making the accounts with iniwrite, in that way i can use arrays on decrypting it (but still not succes at decrypting dunno why it give's me error -1 or yyyy )

- now i really don't get it why it dosen't decrypt it cause it has everything he needs 1 decrypt for each variable that is

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#include <Date.au3>
#include <file.au3>
#include <Array.au3>





$NewUser = GUICreate("New username", 209, 188, -1, -1)
$newuserinput = GUICtrlCreateInput("", 8, 40, 185, 21)
$newupassinput = GUICtrlCreateInput("", 8, 96, 185, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$Createnewuser = GUICtrlCreateButton("&OK", 14, 128, 75, 25, $BS_NOTIFY)
$Cancelnewuser = GUICtrlCreateButton("&Cancel", 111, 128, 75, 25, $BS_NOTIFY)
$EnterPassLabel = GUICtrlCreateLabel("Enter password", 8, 68, 77, 17, 0)
$newusername = GUICtrlCreateLabel("Enter New Username", 8, 16, 105, 17)
$Button1 = GUICtrlCreateButton("Button1", 72, 160, 41, 25)
GUISetState(@SW_SHOW)
_Crypt_Startup()
Global $criptarekey = _Crypt_DeriveKey("parolasuperultrasecreta",$CALG_AES_256)
Global $x=StringReplace(_NowDate(), '/', '-')



While 1
    $nMsg = GUIGetMsg()
    $citescini=IniReadSection($x&".ini", "Accounts");<== i replace this one too from IniReadSectionNames
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $cancelnewuser
            Exitloop
        case $createnewuser
            $Criptatuser = _Crypt_EncryptData(Guictrlread($newuserinput),$criptarekey,$CALG_AES_256);moved here so it encrypts the newsuserinput so arrafindall can find the encrypted version 
             If _ArrayFindAll($citescini,$Criptatuser) Then 
                $Criptatpass = _Crypt_EncryptData(Guictrlread($newupassinput),$Criptarekey,$CalG_Aes_256)
                ;;$a = IniWriteSection($x&".ini",$criptatuser, "password = " & $criptatpass) <<-- this was before
                $a = iniwrite($x&".ini","Accounts",$criptatuser,$criptatpass) ;<<-- this is now but now it dosen't search for it if it has bin search or Not
                MsgBox( 4096, "User Doesn't Exist", "success")
            Else
                MsgBox( 4096, "Username Found", "Imposter! That username already exists!")
            EndIf


        case $button1
                GUISetState(@SW_DISABLE, $newuser)
                $LoginForm = GUICreate("Enter Username & Password", 298, 170, -1, -1)
                $LogInput = GUICtrlCreateInput("", 8, 40, 241, 21)
                $LogInPass = GUICtrlCreateInput("", 8, 96, 241, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
                $OkLogin = GUICtrlCreateButton("&OK", 86, 128, 75, 25, $BS_NOTIFY)
                $ExitLogIn = GUICtrlCreateButton("Exit", 167, 128, 75, 25, $BS_NOTIFY)
                $EnterPassLabel = GUICtrlCreateLabel("Enter password", 8, 68, 77, 17, 0)
                $LogUsername = GUICtrlCreateLabel("Enter Username", 8, 16, 80, 17)
                GUISetState(@SW_SHOW)


                While 1
                $nMsg = GUIGetMsg()
                    Switch $nMsg
                        Case $GUI_EVENT_CLOSE
                            ExitLoop

                        Case $exitlogin
                            exitloop

                        Case $okLogin 
                            $var = IniReadSection($x&".ini", "accounts")
                                If @error Then 
                                    MsgBox(4096, "", "Error occurred, probably no INI file.")
                                Else
                                    For $i = 1 To $var[0][0]
                                        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
                                        $test1 = BinaryToString(_crypt_decryptData(Guictrlread($var[$i][0]),$criptarekey,$CALG_AES_256),1)
                                        $test2 = _crypt_decryptData(Guictrlread($var[$i][1]),$criptarekey,$CALG_AES_256) 
                                        MsgBox(4096, "", "username: " & $test1 & @CRLF & "password: " & $test2)
                                    Next
                                EndIf


                    EndSwitch
                WEnd
            GUISetState(@SW_ENABLE, $newuser)
            GUIDelete($LoginForm)


    EndSwitch
WEnd
_Crypt_DestroyKey($Criptarekey)
_Crypt_Shutdown()

A bit of edit... :

i found out the problem... it was in fron of my eyes

the code should be like this and not how it was on the other code

$test1 = BinaryToString(_crypt_decryptData($var[$i][0],$criptarekey,$CALG_AES_256))
                                        $test2 = BinaryToString(_crypt_decryptData($var[$i][1],$criptarekey,$CALG_AES_256))
Edited by mircea
Link to comment
Share on other sites

Now it's searching for it, and even decrypting it. Thank you very much for the ideea with this code

$citescini=IniReadSectionnames($x&".ini")

or else i wouldn't know how to solve it

Link to comment
Share on other sites

Yes and i thank you for that btw, guess what im stuck again .... can you belive it ?

i don't understand now.. it decrypts de username and password and when i make the comparison nothing... it dosen't do anything

Case $okLogin 
                            $var = IniReadSection($x&".ini", "accounts")
                                If @error Then 
                                    MsgBox(4096, "", "Error occurred, probably no INI file.")
                                Else
                                    For $i = 1 To $var[0][0]
                                        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
                                        $test1 = BinaryToString(_crypt_decryptData($var[$i][0],$criptarekey,$CALG_AES_256))
                                        $test2 = BinaryToString(_crypt_decryptData($var[$i][1],$criptarekey,$CALG_AES_256)) 
                                        MsgBox(4096, "", "username: " & $test1 & @CRLF & "password: " & $test2)
                                    Next
                                        if $test1 = $Loginput Then
                                        Msgbox(0,"Evryika", "Finally it's done")
                                        endif
                                    
                                EndIf

Later edit:

Now i found out that if i exit the program and i enter again i can't decrypt the information that i bin addes before i exit the program

Edited by mircea
Link to comment
Share on other sites

hmm... yep it really does the difference. but still now i think i have a major problem with decrypting the information.

if you try the program and you add some username and password and after that you exit and re-enter the program you will see that the program can't decompile the information again. So, i think, im really stuck here

Link to comment
Share on other sites

it's probably what i said earlyer, and you said befor that, its encrypting the code diffrently everytime, check the ini file befor and after you enter the new account and use the same information, it comes up diffrently.

[spoiler]My UDFs: Login UDF[/spoiler]

Link to comment
Share on other sites

it might be the type of encryption your useing, try switching $CALG_AES_256 with other types of encryption. maybe, im not good with crypt. i know there are diffrent types of encryption from looking at the help file. they show some examples with other types in the function.

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Link to comment
Share on other sites

Exacly what i was thinking for now im trying the $CALG_RC4 cause i seen it on stringencrypt

1 minute later edit:

Nothing still the same thing

Edited by mircea
Link to comment
Share on other sites

I tried your example but don't know why it was writing me -1 in the account and password but now i solve that problem too, now it's finally working

i replace crypting and decrypting with _Stringencrypt and it's perfect

here is the source code maybe it will help you at your login script

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#include <Date.au3>
#include <file.au3>
#include <Array.au3>
#Include <String.au3>





$NewUser = GUICreate("New username", 209, 188, -1, -1)
$newuserinput = GUICtrlCreateInput("", 8, 40, 185, 21)
$newpassinput = GUICtrlCreateInput("", 8, 96, 185, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$Createnewuser = GUICtrlCreateButton("&OK", 14, 128, 75, 25, $BS_NOTIFY)
$Cancelnewuser = GUICtrlCreateButton("&Cancel", 111, 128, 75, 25, $BS_NOTIFY)
$EnterPassLabel = GUICtrlCreateLabel("Enter password", 8, 68, 77, 17, 0)
$newusername = GUICtrlCreateLabel("Enter New Username", 8, 16, 105, 17)
$Button1 = GUICtrlCreateButton("Button1", 72, 160, 41, 25)
GUISetState(@SW_SHOW)
_Crypt_Startup()
Global $criptarekey = "parolasuperultrasecreta"
Global $x=StringReplace(_NowDate(), '/', '-')



While 1
    $nMsg = GUIGetMsg()
    $citescini=IniReadSection($x&".ini", "Accounts");<== i replace this one too from IniReadSectionNames
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $cancelnewuser
            Exitloop
        case $createnewuser
            
            $criptatuser = _StringEncrypt(1,Guictrlread($newuserinput),$criptarekey,1)
             If _ArrayFindAll($citescini,$Criptatuser) Then 
                $criptatpass = _StringEncrypt(1,Guictrlread($newpassinput),$criptarekey,1)
                
                $a = iniwrite($x&".ini","Accounts",$criptatuser,$criptatpass) ;<<-- this is now but now it dosen't search for it if it has bin search or Not
                MsgBox( 4096, "User Doesn't Exist", "success")
            Else
                MsgBox( 4096, "Username Found", "Imposter! That username already exists!")
            EndIf


        case $button1
                GUISetState(@SW_DISABLE, $newuser)
                $LoginForm = GUICreate("Enter Username & Password", 298, 170, -1, -1)
                $LogInput = GUICtrlCreateInput("", 8, 40, 241, 21)
                $LogInPass = GUICtrlCreateInput("", 8, 96, 241, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
                $OkLogin = GUICtrlCreateButton("&OK", 86, 128, 75, 25, $BS_NOTIFY)
                $ExitLogIn = GUICtrlCreateButton("Exit", 167, 128, 75, 25, $BS_NOTIFY)
                $EnterPassLabel = GUICtrlCreateLabel("Enter password", 8, 68, 77, 17, 0)
                $LogUsername = GUICtrlCreateLabel("Enter Username", 8, 16, 80, 17)
                GUISetState(@SW_SHOW)


                While 1
                $nMsg = GUIGetMsg()
                    Switch $nMsg
                        Case $GUI_EVENT_CLOSE
                            ExitLoop

                        Case $exitlogin
                            exitloop

                        Case $okLogin 
                            $var = IniReadSection($x&".ini", "accounts")
                                If @error Then 
                                    MsgBox(4096, "", "Error occurred, probably no INI file.")
                                Else
                                    For $i = 1 To $var[0][0]
                                        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
                                        $test1 = _StringEncrypt(0,$var[$i][0],$criptarekey,1)
                                        $test2 = _StringEncrypt(0,$var[$i][1],$criptarekey,1)
                                        MsgBox(4096, "", "username: " & $test1 & @CRLF & "password: " & $test2)
                                    Next
                                        if $test1 = Guictrlread($Loginput) and $test2 = guictrlread($Loginpass) Then
                                        Msgbox(0,"Evryika", "Finally it's done")
                                        Else
                                            msgbox(0,"Wrong username/password","Wrong username and password")
                                        endif
                                EndIf


                    EndSwitch
                WEnd
            GUISetState(@SW_ENABLE, $newuser)
            GUIDelete($LoginForm)


    EndSwitch
WEnd
_Crypt_DestroyKey($Criptarekey)
_Crypt_Shutdown()
Link to comment
Share on other sites

I fixed your original code because you were trying to decrypt the wrong items after pressing button1.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#include <Date.au3>
#include <file.au3>
#include <Array.au3>





$NewUser = GUICreate("New username", 209, 188, -1, -1)
$newuserinput = GUICtrlCreateInput("", 8, 40, 185, 21)
$newupassinput = GUICtrlCreateInput("", 8, 96, 185, 21);, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
$Createnewuser = GUICtrlCreateButton("&OK", 14, 128, 75, 25, $BS_NOTIFY)
$Cancelnewuser = GUICtrlCreateButton("&Cancel", 111, 128, 75, 25, $BS_NOTIFY)
$EnterPassLabel = GUICtrlCreateLabel("Enter password", 8, 68, 77, 17, 0)
$newusername = GUICtrlCreateLabel("Enter New Username", 8, 16, 105, 17)
$Button1 = GUICtrlCreateButton("Button1", 72, 160, 41, 25)
GUISetState(@SW_SHOW)
_Crypt_Startup()
Global $criptarekey = _Crypt_DeriveKey("parolasuperultrasecreta", $CALG_AES_256)

Global Const $x = StringReplace(_NowDate(), '/', '-')



While 1
    $nMsg = GUIGetMsg()
    $citescini = IniReadSection($x & ".ini", "Accounts");<== i replace this one too from IniReadSectionNames
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Cancelnewuser
            ExitLoop
        Case $Createnewuser
            $Criptatuser = _Crypt_EncryptData(GUICtrlRead($newuserinput), $criptarekey, $CALG_AES_256);moved here so it encrypts the newsuserinput so arrafindall can find the encrypted version
            If _ArrayFindAll($citescini, $Criptatuser) Then
                $Criptatpass = _Crypt_EncryptData(GUICtrlRead($newupassinput), $criptarekey, $CALG_AES_256)
                ;;$a = IniWriteSection($x&".ini",$criptatuser, "password = " & $criptatpass) <<-- this was before
                $a = IniWrite($x & ".ini", "Accounts", $Criptatuser, $Criptatpass) ;<<-- this is now but now it dosen't search for it if it has bin search or Not
                MsgBox(4096, "User Doesn't Exist", "success")
            Else
                MsgBox(4096, "Username Found", "Imposter! That username already exists!")
            EndIf


        Case $Button1
            GUISetState(@SW_DISABLE, $NewUser)
            $LoginForm = GUICreate("Enter Username & Password", 298, 170, -1, -1)
            $LogInput = GUICtrlCreateInput("", 8, 40, 241, 21)
            $LogInPass = GUICtrlCreateInput("", 8, 96, 241, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
            $OkLogin = GUICtrlCreateButton("&OK", 86, 128, 75, 25, $BS_NOTIFY)
            $ExitLogIn = GUICtrlCreateButton("Exit", 167, 128, 75, 25, $BS_NOTIFY)
            $EnterPassLabel = GUICtrlCreateLabel("Enter password", 8, 68, 77, 17, 0)
            $LogUsername = GUICtrlCreateLabel("Enter Username", 8, 16, 80, 17)
            GUISetState(@SW_SHOW)


            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        ExitLoop

                    Case $ExitLogIn
                        ExitLoop

                    Case $OkLogin
                        $var = IniReadSection($x & ".ini", "accounts")
                        If @error Then
                            MsgBox(4096, "", "Error occurred, probably no INI file.")
                        Else
                            For $i = 1 To $var[0][0]
                                MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
                                $test1 = BinaryToString(_Crypt_DecryptData($var[$i][0], $criptarekey, $CALG_AES_256), 1)
                                $test2 = BinaryToString(_Crypt_DecryptData(IniRead($x & ".ini", "accounts", $var[$i][0], ""), $criptarekey, $CALG_AES_256), 1)
                                MsgBox(4096, "$I = " & $i, "username: " & $test1 & @CRLF & "password: " & $test2)
                            Next
                        EndIf


                EndSwitch
            WEnd
            GUISetState(@SW_ENABLE, $NewUser)
            GUIDelete($LoginForm)


    EndSwitch
WEnd
_Crypt_DestroyKey($criptarekey)
_Crypt_Shutdown()

Try this and see if it works for you.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@pieeater thank you very much but i still must do something with the code cause it seems that it searchs only the first one and comparsed with the loginput and loginpass the other ones dosen't read and compared

Case $okLogin 
                            $var = IniReadSection($x&".ini", "accounts")
                                If @error Then 
                                    MsgBox(4096, "", "Error occurred, probably no INI file.")
                                Else
                                    For $i = 1 To $var[0][0]
                                        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
                                        $test1 = _StringEncrypt(0,$var[$i][0],$criptarekey,1)
                                        $test2 = _StringEncrypt(0,$var[$i][1],$criptarekey,1)
                                        MsgBox(4096, "", "username: " & $test1 & @CRLF & "password: " & $test2)
                                    Next
                                        if $test1 = Guictrlread($Loginput) and $test2 = guictrlread($Loginpass) Then
                                        Msgbox(0,"Evryika", "Finally it's done")
                                        Else
                                            msgbox(0,"Wrong username/password","Wrong username and password")
                                        endif
                                EndIf

@ BrewManNH i tried and yes it's working perfectley now im comparing with my old one to see were i did wrong. Btw to do does decrypting the information after you exit the aplication and re-enter it ?

Guys i want to thank you very much for the help.

Link to comment
Share on other sites

It should decrypt the data entered no matter how many times you close it out and restart it. Your original code was trying to decrypt the data entered in the input boxes, rather than what is inside your .ini files. I changed it so that it will read from the .ini files and decrypt that.

Your second GUI that opens when you hit button1 isn't really needed other than the OK button, at least as your code is written above because you're not checking the data in it against what's in the ini file, but Ii figured it was a work in progress at this point to get the essentials to work.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

Maybe this will help:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...