Jump to content

[solved]Problems with encrypt/Decrypt


Recommended Posts

Hello guys.

Im trying to make a interface were i can add new username and new passwords but i want to encrypt the password and the username in a .ini file

The problem is when i try to decrypt the password and the username.

I have another question, how can i make it to add automaticly a new line

For example when you make a username and password it will add in a .ini file and i want to each time when i add a new username and password to add new lines and not to replace the actual line. i hope you understand what im trying to say

thank you

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#include <Date.au3>
#include <file.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)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $cancelnewuser
            Exitloop
        case $createnewuser
            _Crypt_Startup()
            $criptarekey = _Crypt_DeriveKey("parolasuperultrasecreta",$CALG_AES_256)
            $Criptatuser = _Crypt_EncryptData(Guictrlread($newuserinput),$criptarekey,$CALG_AES_256)
            $Criptatpass = _Crypt_EncryptData(Guictrlread($newupassinput),$Criptarekey,$CalG_Aes_256)
            $x = _NowDate()
            $a = IniWrite($x&".ini","accounts","name",$criptatuser)
            $b = IniWrite($x&".ini","accounts","passwd",$criptatpass)
            
            
            $iniread = IniRead($X&".ini","accounts","name","")
            $iniread2 = iniread($X&".ini","accounts","name","")
            $a1 = _Crypt_DecryptData($iniread,$criptarekey,$CALG_AES_256)
            $a2 = _Crypt_DecryptData($iniread2,$criptarekey,$CALG_AES_256)
            
            Msgbox(0,"Testare Decriptare",$a1)
            msgbox(0,"Test 2",$a2)
            msgbox(0,"asd",$iniread)
            _Crypt_DestroyKey($Criptarekey)
            _Crypt_Shutdown()
    EndSwitch
WEnd
Edited by mircea
Link to comment
Share on other sites

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

You're reading "name" twice but not "password" value back.

Now, beware that "parolasuperultrasecreta" is in plaintext in your script...

This isn't secure against a determined opponent.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Ok but still it dosen't work, i tried to remove the _Crypt_DeriveKey and replace it with $Crypt = "test123" and after that replace each encrypt data but still nothing it dosen't want to decrypt the text.

And do you know any metod to imrpove the encrypt with the derivekey? if you say it's not so secure?

Thank you

Link to comment
Share on other sites

The date contains slashes but IniWrite doesn't create subdirs.

Read data is binary: need conversion.

Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#include <Date.au3>
#include <file.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)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $cancelnewuser
            Exitloop
        case $createnewuser
            _Crypt_Startup()
            $criptarekey = _Crypt_DeriveKey("parolasuperultrasecreta",$CALG_AES_256)
            $Criptatuser = _Crypt_EncryptData(Guictrlread($newuserinput),$criptarekey,$CALG_AES_256)
            $Criptatpass = _Crypt_EncryptData(Guictrlread($newupassinput),$Criptarekey,$CalG_Aes_256)
            $x = StringReplace(_NowDate(), '/', '-')
            $a = IniWrite($x&".ini","accounts","name",$criptatuser)
            $b = IniWrite($x&".ini","accounts","passwd",$criptatpass)


            $iniread = IniRead($X&".ini","accounts","name","")
            $iniread2 = iniread($X&".ini","accounts","passwd","")
            $a1 = BinaryToString(_Crypt_DecryptData($iniread,$criptarekey,$CALG_AES_256))
            $a2 = BinaryToString(_Crypt_DecryptData($iniread2,$criptarekey,$CALG_AES_256))

            Msgbox(0,"Testare Decriptare",$a1)
            msgbox(0,"Test 2",$a2)
            msgbox(0,"asd",$iniread)
            _Crypt_DestroyKey($Criptarekey)
            _Crypt_Shutdown()
    EndSwitch
WEnd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thank you very much for the help @jchd. So if i get it right each time i will encrypt something in a file (.ini, .txt) when i want to decrypt it i will have to use conversion from binary to string so it can decrypt.

And do you know a method to add new lines automaticly cause when i try to add new username and password it rewrites the old one.

i was thinking at something like this

Something like this .. i was thinking but i don't know if it's right (the source code from the code it's not i know that but thinking at somethings like this

if iniwrite("something.ini","Accounts",$cryptusername) not "" 
    then IniWrite
Else addnewline
    Endif
Link to comment
Share on other sites

I read this to mean that you may have other sections in you .INI file. In that case you may not want to make your .INI file like this (actual password strings will be encrypted):

[John]

pwd=john's password

[Joe]

pwd=ThiS_Is 1 (one) password for UsEr jOe

Just because you might have a user creaing a login similar to a section _you_ use in you program.

To avoid that, you can make the .INI file this way (actual password strings will be encrypted):

[(John)]

pwd=john's password

[(Joe)]

pwd=ThiS_Is 1 (one) password for UsEr jOe

adding parenthesis (as an example) around the actual user name and not using parenthesis around sections names that your program uses.

Another simple possibility:

[Accounts]

pwd_John=john's password

pwd_Joe=ThiS_Is 1 (one) password for UsEr jOe

[Another_Section]

Still, the key string is essentially in clear in your executable and AutoIt executables are not protectible against determined opponents (no executable is completely protectible). I mean that if the value gained by taking pain to collect the user/password set is non-negligible, then it can be done relatively easily. If all you care is to keep away your sister kid, then don't worry much.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thank you so much for your help i found out the string encrypt and seems like it's very hardcore encrypt and i could i think use both crypt.au3 and string encrypt but that's too much for what i need, i only need to make it a little private, no one it's going to decrypt the text and so on but it's better then open the .ini file and there he can see the username and password.

i hope i will not have any more problems.

Thank you for the guide

Link to comment
Share on other sites

You're welcome. Good luck!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Seems im stuck again. I managed a way to read and decrypt the key and he value but now im stuck when i want to log in

The mesage box confirm me that i have introduce everything right but i don't understand why it dosen't make the selection ...

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#include <Date.au3>
#include <file.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)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $cancelnewuser
            Exitloop
        case $createnewuser
            
            $Criptatuser = _Crypt_EncryptData(Guictrlread($newuserinput),$criptarekey,$CALG_AES_256)
            $Criptatpass = _Crypt_EncryptData(Guictrlread($newupassinput),$Criptarekey,$CalG_Aes_256)
            $x = _NowDate()
            $a = IniWrite($x&".ini","accounts",$criptatuser,$criptatpass)
    #comments-start     
            ;$var = IniReadSection($x&".ini","accounts")
        ;   
            ;$iniread = IniRead($X&".ini","accounts",$criptatuser,$criptatpass)
            ;$ads = iniread($X&".ini","accounts","","")
        ;   For $i = 1 To $var[0][0]
            ;   MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
            ;   $a1 = BinaryToString (_Crypt_DecryptData($var[$i][0],$criptarekey,$CALG_AES_256))
        ;       $ax = BinaryToString(_Crypt_DecryptData($var[$i][1],$criptarekey,$CALG_AES_256))
        ;   Next
        ;   
        ;   Msgbox(0,"key", $A1)
        ;   msgbox(0,"value", $Ax)          
    #comments-end   
    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")
            
                            $iniread = IniRead($X&".ini","accounts",$criptatuser,$criptatpass)
                            $ads = iniread($X&".ini","accounts","","")
                            For $i = 1 To $var[0][0]
                                MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
                                $a1 = BinaryToString (_Crypt_DecryptData($var[$i][0],$criptarekey,$CALG_AES_256))
                                $ax = BinaryToString(_Crypt_DecryptData($var[$i][1],$criptarekey,$CALG_AES_256))
                            Next
            
                            Msgbox(0,"key", $A1)
                            msgbox(0,"value", $Ax)  
                                If not Guictrlread($LogInput) Or Guictrlread($LogInPass) = "" Then ;; verifica daca ai introdus parola sau username-ul e prima casuta de IF (1)
                                    Msgbox (0,"Enter username/password", "Please enter username and/or password")
                                Else 
                                    if Guictrlread($Loginput) or GuictrlRead($Loginpass) = $a1 or $ax Then
                                        Msgbox(0,"Welcome", "You have succesefuly log in")
                                    Endif
                                endif

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

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

After i searched the forum i found one topic -> <<-- were he had resolved my problem to search for passwords and username's and for that i want to say thank you very very much both for bwochinski and pieeater.

but seems im stuck again it's say incorect number of parameters in function call i tried to search the help file. to remake it but no help i try to convert from stringtobinary but still no luck.

#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 = _NowDate()
Global $citescini=IniReadSectionNames($x&".ini")


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $cancelnewuser
            Exitloop
        case $createnewuser
             If _ArrayFindAll($citescini,GUICtrlRead($newuserinput),1) Then
                $Criptatuser = _Crypt_EncryptData(Guictrlread($newuserinput),$criptarekey,$CALG_AES_256)
                $Criptatpass = _Crypt_EncryptData(Guictrlread($newupassinput),$Criptarekey,$CalG_Aes_256)
                
            
                $a = IniWriteSection($x&".ini",$criptatuser), "password = " & $criptatpass) ;; givs me error. incorect number of parameters in function call
                
                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")
            
                            $iniread = IniRead($X&".ini","accounts",$criptatuser,$criptatpass)
                            $ads = iniread($X&".ini","accounts","","")
                            For $i = 1 To $var[0][0]
                                MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
                                $a1 = BinaryToString (_Crypt_DecryptData($var[$i][0],$criptarekey,$CALG_AES_256))
                                $ax = BinaryToString(_Crypt_DecryptData($var[$i][1],$criptarekey,$CALG_AES_256))
                            Next
            
                            Msgbox(0,"key", $A1)
                            msgbox(0,"value", $Ax)  
                                If not Guictrlread($LogInput) Or Guictrlread($LogInPass) = "" Then ;; verifica daca ai introdus parola sau username-ul e prima casuta de IF (1)
                                    Msgbox (0,"Enter username/password", "Please enter username and/or password")
                                Else 
                                    if Guictrlread($Loginput) or GuictrlRead($Loginpass) = $a1 or $ax Then
                                        Msgbox(0,"Welcome", "You have succesefuly log in")
                                    Endif
                                endif

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

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

Looks like an extra parenthesis on the line you're getting an error on...

$a = IniWriteSection($x&".ini",$criptatuser), "password = " & $criptatpass)
                                           ^
                                           |
                            Get rid of this guy
Edited by bwochinski
Link to comment
Share on other sites

ok now this is lame... i really feel so ... i think you know what i mean.

Thank you my god... and each time i was searching for the iniwritesection i was thinking i didn't right it good or something.

Link to comment
Share on other sites

Now i don't understand something i put the condition to check on it if the input username has bin chosen and still it dosen't compare it why it's that ? i put the condition to decrypt the informatins in the same if and still nothing

Later edit:

I found out that the problem it is in the _crypt_decryptdata, he dosen't read the .ini file for the section. I think i will manage a way to do it (cross fingers)

Later Later edit:

Seems im really stuck i didn't manage a way to make it read the section name. I hope someone could help me or guilde me to find out were i made the mistake and were i did it wrong

#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 = _NowDate()
Global $citescini=IniReadSectionNames($x&".ini")


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $cancelnewuser
            Exitloop
        case $createnewuser
             If _ArrayFindAll($citescini,GUICtrlRead($newuserinput),1) <> BinaryToString(_Crypt_DecryptData($newuserinput,$criptarekey,$CALG_AES_256)) Then ;; here is the problem he compares the inputname with the encrypt name and thats why he dosent seem to find the same one
                $Criptatuser = _Crypt_EncryptData(Guictrlread($newuserinput),$criptarekey,$CALG_AES_256)
                $Criptatpass = _Crypt_EncryptData(Guictrlread($newupassinput),$Criptarekey,$CalG_Aes_256)
                
            
                $a = IniWriteSection($x&".ini",$criptatuser, "password = " & $criptatpass)
                
                MsgBox( 4096, "User Doesn't Exist", "success")
            Else
                $check = BinaryToString(_crypt_decryptData($newuserinput,$criptarekey,$CALG_AES_256)
                
                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

                            $a = IniRead($x&".ini", GUICtrlRead($Loginput), "password", -395724618)
                            If $a <> -395724618 And $a == GUICtrlRead($loginpass) Then   ;<===== this is where im having trouble
                                msgbox(0,"a mers", "ceau")
                            Else
                                MsgBox(4096,"Access denied","Please Try Again")
                            EndIf

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

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

Still nothing i tried to replace

If _ArrayFindAll($citescini,GUICtrlRead($newuserinput),1) <> BinaryToString(_Crypt_DecryptData($newuserinput,$criptarekey,$CALG_AES_256)) Then ;; here is the problem he compares the inputname with the encrypt name and thats why he dosent seem to find the same one

with

If _ArrayFindAll($citescini,_Crypt_EncryptData(Guictrlread($newuserinput),$criptarekey,$CALG_AES_256),1) Then

but still nothing. I know i have to decrypt the username's from the .ini file and after that compare it with the $newuserinput but the prolem is i don't know how to implement it.

Link to comment
Share on other sites

I don't think so, cause it makes the .ini file, it writes there anything it needs like the username and password encrypted so, that step it's done. The problem is when i try to make another accounts (another username) for the if and else command to compare it i need to decrypt the information from the .ini file and i don't know how to implement that.

The cause of the problem i think it's that when i try to encrypt it dosen't give the same encrypt data and that maybe the main cause

Link to comment
Share on other sites

like i said it wasnt making the ini file, you had this part wrong:

global $x = _NowDate()

heres the code that i got working up untill the login, it still needs to be decrypted.

#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=IniReadSectionNames($x&".ini");<== moved here so it is constantly checking instead of just once
    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)
                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

                            $a = IniRead($x&".ini", GUICtrlRead($Loginput), "password", -395724618)
                            If $a <> -395724618 And $a == GUICtrlRead($loginpass) Then   ;<===== this is where im having trouble
                                msgbox(0,"a mers", "ceau")
                            Else
                                MsgBox(4096,"Access denied","Please Try Again")
                            EndIf

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


    EndSwitch
WEnd
_Crypt_DestroyKey($Criptarekey)
_Crypt_Shutdown()
Edited by pieeater

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

Link to comment
Share on other sites

Hmmm... i never think that could be the problem with the ini. But now seems im stuck at decrypting. It's funny cause i don't understand some things over here, like;

I understand from what you show me how can i add new usernames and passwords and to check if the username hasn't bin added yet. But im stuck again with decrypting now .... (i feel so lame)... i tried to copy the method you showed me with the encrypt and only change from encrypt to decrypt but the problem is how can i make read the ini file the section and the password cause the decrypt formula it's simple.

Here is what i tried.

#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=IniReadSectionNames($x&".ini");<== moved here so it is constantly checking instead of just once
    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)
                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

                            $varx = IniReadsection($x&".ini",Guictrlread($loginput)) ;; i made the readsection) 

                            
                            If $varx <> -395724618 And $varx == BinaryToString(_crypt_decryptData(Guictrlread($loginpass),$criptarekey,$CALG_AES_256)) Then   ;<==id use your ideea here 
                                MsgBox(0,"test","It's working oh my dgod ... imposibile")
                            Else
                                MsgBox(4096,"Access denied","Please Try Again")
                            EndIf


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


    EndSwitch
WEnd
_Crypt_DestroyKey($Criptarekey)
_Crypt_Shutdown()

Later edit:

Tried to replace the _Cript_decriptdata but still nothing it give's me error -1 and i think that means that it dosen't open the file or can't read

Case $okLogin

                            
                            $varx = _Crypt_DecryptData(inireadsectionnames($x&".ini"),$criptarekey,$CALG_AES_256)
                            
                            msgbox(0,"asd",$varx)
                            If $varx <> -395724618 And $varx == BinaryToString(_crypt_decryptData(Guictrlread($loginpass),$criptarekey,$CALG_AES_256)) Then   ;<==id use your ideea here 
                                MsgBox(0,"test","It's working oh my dgod ... imposibile")
                            Else
                                MsgBox(4096,"Access denied","Please Try Again")
                            EndIf
Edited by mircea
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...