Page 1 of 1

executing function for each username/password

Posted: 28 Apr 2024, 16:24
by jaccotjuhhh
yes hello and hi
i have big code thats doing exactly what i want.
but now i have to do this for multiple accounts.
i have an INI file containing settings.
this script is one i use privately so i have no need for making it hack-proof.

lets say for this example i have this part of my INI file:

Code: Select all

[credentials1]
username=john
password=123
[credentials2]
username=joe
password=321
[credentials3]
username=jan
password=1234
how can i achieve something that i would sketch as:

Code: Select all

inipath := A_WorkingDir "\data\config.ini"
inifile := Fileread(inipath)
for username in inifile{
funtion1(username, password)
}
so in english: how can i execute function1 for multiple username/passwords?

Re: executing function for each username/password  Topic is solved

Posted: 28 Apr 2024, 16:53
by mikeyww
Hello,

Use :arrow: IniRead to read your INI file.

Code: Select all

#Requires AutoHotkey v2.0
ini           := 'config.ini'
sectionNames  := IniRead(ini)
For section in StrSplit(sectionNames, '`n') {
 user := IniRead(ini, section, 'username')
 pwd  := IniRead(ini, section, 'password')
 f(user, pwd)
}

f(user, pwd) {
 MsgBox 'User       :  ' user '`nPassword: ' pwd, 'Information'
}

Re: executing function for each username/password

Posted: 29 Apr 2024, 09:40
by jaccotjuhhh
@mikeyww hi MikeyWW Thanks so much!
How would you approach if the INI file also contains other unrelated sections?
I'm having trouble applying a correct strsplit for that..
My route would be to

Code: Select all

try
each section but im not sure if that's a good route.

Re: executing function for each username/password

Posted: 29 Apr 2024, 09:52
by mikeyww
That is OK if it works. I also recommend reading the documentation section pertaining to the "Default" parameter.