Jump to content

IniReadSection


AutID
 Share

Recommended Posts

Hello,
I have an .ini file like this

[Names]
name1=John
name2=Marry
name3=Ben

[Passwwords]
pass1=123
pass2=213
pass3=321

In my gui i have a combo which will display all the names from the .ini file and a simple input which will load the password.
The names and the passwords will be saved after the gui exists so the sections of the name and the password will depend on the accounts the user has.

How can i load the matching password by only choosing the name on the combo???

Edit: here is a small reproducer so you can work with in case you want to help.

#include <EditConstants.au3>
Local $names = IniReadSection("settings.ini", "tittle")
$hGUI = GUICreate("", 340, 120)
$lName = GUICtrlCreateLabel("Name: ", 10, 10)
$lPassword = GUICtrlCreateLabel("Password: ", 10, 35)
$iName = GUICtrlCreateCombo("", 80, 10, 150)
$iPassword = GUICtrlCreateInput("", 80, 35, 150, 20, $ES_PASSWORD)
GUICtrlSetLimit($iPassword, 20)
$Login = GUICtrlCreateButton("Log in", 10, 100, 320, 20)
For $i = 1 To $names[0][0]
 GUICtrlSetData($iName, $names[$i][1])
Next
GUISetState()
While 1
 If GUIGetMsg() = -3 Then ExitLoop
WEnd
Edited by AutID
Link to comment
Share on other sites

Why don't you assign the password to the name instead of having them in 2 unrelated sections?

The thing about ini files is that in general it will add new items to the end of the section, but it isn't a requirement of the "standard" for ini files. So to be sure that the correct user name is associated with the correct password, you should do it like this.

 

[section name]

John=123

Mary=213

Ben=321

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

I came up with this. It is pretty fine.

#include <EditConstants.au3>
Local $names = IniReadSection("settings.ini", "Names")
Local $names2 = IniReadSection("settings.ini", "Passwords")
$hGUI = GUICreate('', 340, 120)
$lName = GUICtrlCreateLabel("Name: ", 10, 10)
$lPassword = GUICtrlCreateLabel("Password: ", 10, 35)
$iName = GUICtrlCreateCombo("", 80, 10, 150)
$iPassword = GUICtrlCreateInput("", 80, 35, 150, 20)
GUICtrlSetLimit($iPassword, 20)
$Login = GUICtrlCreateButton("Log in", 10, 100, 320, 20)
For $i = 1 To $names[0][0]
 GUICtrlSetData($iName, $names[$i][1])
Next
GUISetState()
Local $c = 0
Local $b = 0
While 1
 $msg = GUIGetMsg()
 Switch $msg
  Case -3
   Exit
  Case $iName
   Local $read = GUICtrlRead($iName)
   For $i = 0 To UBound($names)-1
    If StringInStr($names[$i][1], $read) Then
     ExitLoop
    Else
     $c += 1
    EndIf
   Next
   For $i = 1 To UBound($names2)-1
    $b += 1
    If $b = $c Then GUICtrlSetData($iPassword, $names2[$i][1])
   Next
   $b = 0
   $c = 0
 EndSwitch
WEnd

If anyone has some other suggestions then i would be happy to see them.

Link to comment
Share on other sites

Why don't you assign the password to the name instead of having them in 2 unrelated sections?

The thing about ini files is that in general it will add new items to the end of the section, but it isn't a requirement of the "standard" for ini files. So to be sure that the correct user name is associated with the correct password, you should do it like this.

I thought about it but i find better coding separeting names from passwords. However what you suggest takes much less coding and troubles. Don't know why i want it this way...

Edit: I did it that way. IniReadSection returns an array which is much easier to work with.

Cheers

 

Edited by AutID
Link to comment
Share on other sites

^^

$users = IniReadSection("settings.ini", "users")   ; using one section (as Brewmannh said) named "users"
$hGUI = GUICreate('', 340, 120)
$lName = GUICtrlCreateLabel("Name: ", 10, 10)
$lPassword = GUICtrlCreateLabel("Password: ", 10, 35)
$iName = GUICtrlCreateCombo("", 80, 10, 150)
$iPassword = GUICtrlCreateInput("", 80, 35, 150, 20)
GUICtrlSetLimit($iPassword, 20)
$Login = GUICtrlCreateButton("Log in", 10, 100, 320, 20)
For $i = 1 To $users[0][0]
 GUICtrlSetData($iName, $users[$i][0])
Next
GUISetState()

While 1
 $msg = GUIGetMsg()
 Switch $msg
  Case -3
      Exit
  Case $iName
      $read = GUICtrlRead($iName)
      For $i = 1 To $users[0][0]
          If $read = $users[$i][0] Then GUICtrlSetData($iPassword, $users[$i][1])
      Next
 EndSwitch
WEnd
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...