Sign in to follow this  
Followers 0
xPloit

I fail @ ini commands

11 posts in this topic

#1 ·  Posted (edited)

Title pretty much says it all...

I'm working on a password saver program that will encrypt the passwords and write them into different sections of an ini file.

The section is titled after whatever the password is used for (gmail, bank, etc.)

The username and password shouldn't need explaining...

I have everything done except for the IniReadSection() part, which is throwing me off. How do I make it read all the sections in the .ini file and compare it to the given section to read from? If I could figure that out, I can split it, decrypt it, and msgbox it out...

Here is my code for reference. I commented where I want the IniReadsection() to be and what I want done and all that. Feel free to comment on other parts that you see are poorly coded / useless / etc. All feedback is appreciated!

#Include <GUIConstants.au3>
#Include <String.au3>
#Include <Array.au3>
#Include <File.au3>
AutoItSetOption("MustDeclareVars",1)
AutoItSetOption("GUIOnEventMode",1)

Global $GUI = GUICreate("Password Saver",300,220)
    GUISetOnEvent($GUI_EVENT_CLOSE,"_Close")
Global $EncryptionLevelLabel = GUICtrlCreateLabel("Encryption Level: ",10,10,90,20)
Global $EncryptionLevel = GUICtrlCreateInput("",100,8,80,20)
Global $EncryptionPasswordLabel = GUICtrlCreateLabel("Password: ",10,38,70,20)
Global $EncryptionPassword = GUICtrlCreateInput("",65,35,200,20)
Global $SectionLabel = GUICtrlCreateLabel("Description: ",10,80,55,30)
Global $Section = GUICtrlCreateInput("",70,78,195,20)
Global $UsernameLabel = GUICtrlCreateLabel("Username: ",10,112,50,30)
Global $Username = GUICtrlCreateInput("",70,110,195,20)
Global $PasswordLabel = GUICtrlCreateLabel("Password: ",10,143,70,20)
Global $Password = GUICtrlCreateInput("",65,140,200,20)
Global $Save = GUICtrlCreateButton("Save",30,175,60,30)
    GUICtrlSetOnEvent($Save,"_Save")
Global $Load = GUICtrlCreateButton("Load",110,175,60,30)
    GUICtrlSetOnEvent($Load,"_Load")
Global $Help = GUICtrlCreateButton("Help",185,8,80,20)
    GUICtrlSetOnEvent($Help,"_Help")
Global $Exit = GUICtrlCreateButton("Exit",240,175,50,30)
    GUICtrlSetOnEvent($Exit,"_Close")

Global $iniFile = "Passwords.ini"
Dim $Split

GUISetState()

While 1
    Sleep(10)
    
    If Not FileExists($iniFile) Then
        IniWriteSection($iniFile,"WARNING","THIS IS A SECURE AND ENCRYPTED FILE.  AUTHORIZED USERS ONLY!")
    ElseIf GUICtrlRead($EncryptionLevel) > 5 Then
        TrayTip("Password Saver","Please select a smaller encryption level!",5)
        GUICtrlSetData($EncryptionLevel,"")
    EndIf
WEnd

Func _Save()
    If GUICtrlRead($EncryptionLevel) = "" Then
        TrayTip("Password Saver","You must define an encryption level!",5)
        Return
    ElseIf GUICtrlRead($EncryptionPassword) = "" Then
        TrayTip("Password Saver","You must define an encryption password!",5)
        Return
    ElseIf GUICtrlRead($Section) = "" Then
        TrayTip("Password Saver","You must include a description!",5)
        Return
    ElseIf GUICtrlRead($Username) = "" Then
        TrayTip("Password Saver","You must include your username!",5)
        Return
    ElseIf GUICtrlRead($Password) = "" Then
        TrayTip("Password Saver","You must include your password!",5)
        Return
    EndIf
    
    Local $EncryptedPassword = _StringEncrypt(1,GUICtrlRead($Password),GUICtrlRead($EncryptionPassword),GUICtrlRead($EncryptionLevel))
    
    IniWrite($iniFile,GUICtrlRead($Section),GUICtrlRead($Username),$EncryptedPassword)
    
    GUICtrlSetData($EncryptionLevel,"")
    GUICtrlSetData($EncryptionPassword,"")
    GUICtrlSetData($Section,"")
    GUICtrlSetData($Username,"")
    GUICtrlSetData($Password,"")
    
    TrayTip("Password Saver","Password successfully stored!",5)
EndFunc

Func _Load()
    If GUICtrlRead($EncryptionLevel) = "" Then
        TrayTip("Password Saver","You must define an encryption level!",5)
        Return
    ElseIf GUICtrlRead($EncryptionPassword) = "" Then
        TrayTip("Password Saver","You must define an encryption password!",5)
        Return
    ElseIf GUICtrlRead($Section) = "" Then
        TrayTip("Password Saver","You must include the description!",5)
        Return
    EndIf
    
    Local $iniSection = IniReadSectionNames($iniFile)

    For $i = 1 To $iniSection[0]
        Local $iniData = IniReadSection($iniFile,$iniSection[$i])
        For $j = 1 To $iniData[0][0]
            MsgBox(0,"",$iniSection[$i] & @CRLF & @TAB & "Username: " & $iniData[$j][0] & @CRLF & @TAB & "Password: " & _StringEncrypt(0,$iniData[$j][1],GUICtrlRead($EncryptionPassword),GUICtrlRead($EncryptionLevel)))
        Next
    Next
EndFunc

Func _Help()
    MsgBox(0,"HELP","If you don't know how to use this, then it is not yours" & @CRLF & "Please return it" & @CRLF & "You might be a cookie if you do :)")
EndFunc

Func _Close()
    Exit
EndFunc
Edited by xPloit

00101101011110000101000001101100011011110110100101110100

Share this post


Link to post
Share on other sites



Do you really mean "section name" or do you actually mean "key name"?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

[sECTION] <-- Bank/Gmail/etc

Key=Value

Key = Username

Value = Password

I was hoping for it to find the section, decrypt the value and display all 3

Edited by xPloit

00101101011110000101000001101100011011110110100101110100

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$ini = "sample.ini"

$section = IniReadSectionNames ( $ini )

For $i = 1 To $section[0]
    $data = IniReadSection($ini,$section[$i])
    For $j = 1 To $data[0][0]
        MsgBox(0,$section[$i],"Key = "&$data[$j][0]&@CRLF&"Value = "&_Decrypt($data[$j][1]))
    Next
Next

Func _Decrypt($pass); dummy encryption func
    Return BinaryToString($pass)
EndFunc

sample.ini

[gmail]

gary=0x31323334

[hotmail]

spongebob=0x34353637

Edited by Mison

Hi ;)

Share this post


Link to post
Share on other sites

IniReadSectionNames lol, can't believe I didn't see that >.< I literally had this exact same code before I posted, except with IniReadSection...

Anyway,I have an error and I don't understand why I'm getting it. I posted my code (directly below) and the error message (below that)

Local $iniSection = IniReadSectionNames($iniFile)
    
    For $i = 1 To $iniSection[0]
        Local $iniData = IniReadSection($iniFile,$iniSection[$i])
        For $j = 1 To $iniData[0][0]
            MsgBox(0,"",$iniSection[$i] & @CRLF & @TAB & "Username: " & $iniData[$j][0] & @CRLF & @TAB & "Password: " & _StringEncrypt(0,$iniData[$j][1],GUICtrlRead($EncryptionPassword),GUICtrlRead($EncryptionLevel)))
        Next
    Next

C:\Users\Justin\Documents\AuI\Password Saver.au3 (93) : ==> Subscript used with non-Array variable.:
For $j = 1 To $iniData[0][0]
For $j = 1 To $iniData^ ERROR

Anybody know why $iniData isn't returning as an array?


00101101011110000101000001101100011011110110100101110100

Share this post


Link to post
Share on other sites

*bump

I still need help figuring out why $iniData isn't an array...


00101101011110000101000001101100011011110110100101110100

Share this post


Link to post
Share on other sites

xPloit,

Almost certainly because the section is empty. Although the Help file says that an error is due to "The INI file may not exist or the section may not exist", the function also errors if the section is empty. ;)

Just test for @error before trying to loop through the array.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

i tested two times for @error. Once before each array check. The first one works, but it crashes before the second one.

The section is definitely not empty...

This is the part of my ini i'm trying to read from

[AuI Forums]
xPloit=BA97A3104248C44C97976D94550ED1ACAF7AEA7224C585642587D8EB8D081FF1536D47A16B2D4A438350B0C93D58AA736285D8DF031B55F4903ED6A3BC31F6BB96B616921D03ABFA89D651730A31CD0EBE054E9DB7423108AFCBCA7172F754A005EF9AB8E9574150D3D8AD622A4884BA33E6AFE028BEA3A1323C88123A4F1E891A5564D5C32B9D0186B112D4DE3C4DD7B7DCE47FDD57212EDE26A46D4A78C2D180D9AACB14C23C772D5B934C8401409D766ED518604524D303BCC03061D820B39D90562AB49D40AC03F1BFC0EF4C94DBA251CD8FAD3E4C9D443A2530E5A1FB8A103C2F7D29CC0B8E03D0F4A4C25CFA4DC9AFE3331285EE993B6FB6F34C10A24DA8760060AAC65A8639B5BE7A5F1EF36FB85A1C5DBBDF52D1CCAB6198DD535309

I type in my encryption level and encryption password. Then I type in "AuI Forums" (without quotes) and hit Load. It obviously exists, but for some reason it doesn't find it maybe?

***EDIT***

I just updated my OP with my latest code. Not sure what changes I made, but I know I've made a few...

Edited by xPloit

00101101011110000101000001101100011011110110100101110100

Share this post


Link to post
Share on other sites

It's erroring because your first section contains this information:

[WARNING]
THIS IS A SECURE AND ENCRYPTED FILE.  AUTHORIZED USERS ONLY!

As you can see, there's a "Key" but no value, so it's not returning an array which is why you get the error. You need to rewrite your code so that the first section either doesn't exist, or you have a proper Key=Value in it.


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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

thanks, Brew! Works like a charm, haha.

Just had a quick problem with it displaying every section rather than just the one I typed into the section box. But that was an easy fix ;)

Thanks for all the help everybody!

Edited by xPloit

00101101011110000101000001101100011011110110100101110100

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I was thinking on this, and came up with an alternate plan for you to try.

Instead of this

For $i = 1 To $iniSection[0]
        Local $iniData = IniReadSection($iniFile,$iniSection[$i])
        For $j = 1 To $iniData[0][0]
            MsgBox(0,"",$iniSection[$i] & @CRLF & @TAB & "Username: " & $iniData[$j][0] & @CRLF & @TAB & "Password: " & _StringEncrypt(0,$iniData[$j][1],GUICtrlRead($EncryptionPassword),GUICtrlRead($EncryptionLevel)))
        Next
    Next

Use this code in its place.

For $i = 2 To $iniSection[0] ; <<<<<<< NOTE the change in this line
        Local $iniData = IniReadSection($iniFile,$iniSection[$i])
        For $j = 1 To $iniData[0][0] 
            MsgBox(0,"",$iniSection[$i] & @CRLF & @TAB & "Username: " & $iniData[$j][0] & @CRLF & @TAB & "Password: " & _StringEncrypt(0,$iniData[$j][1],GUICtrlRead($EncryptionPassword),GUICtrlRead($EncryptionLevel)))
        Next
    Next

This will allow you to keep the INI file the same, but will skip the first section. Of course this will only work correctly if you keep the INI file in the same format every time that it's created.

Edited by BrewManNH

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

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