I made a script in 20 minutes…
Is there a way to improve this script?
set theuser to paragraphs of "ahole45\nbart33\npiemyeye\nyeahme1\nyoufailed4"
set thepass to paragraphs of "mypass663\nlisawmarge\nfound25\nyourmom2u\n2rich4u"
set numb to 0
set thelist to ""
if (count theuser) = (count thepass) then
repeat until numb = (count theuser)
set numb to numb + 1
set user to item numb of theuser
set pass to item numb of thepass
set thespace to " "
if numb is 1 then set thespace to ""
if not numb = (count theuser) then
set mypoint to thespace & "{name:\"" & user & "\", password:\"" & pass & "\"},"
else
set mypoint to thespace & "{name:\"" & user & "\", password:\"" & pass & "\"}"
end if
set thelist to thelist & mypoint
end repeat
set thelist to "{" & thelist & "}"
set thelist to run script thelist
else
error "The number of usernames in not equal to the number of passwords." number -1 from {theuser} & {thepass}
end if
set myuser to name of item 3 of thelist
set mypass to password of item 3 of thelist
display dialog myuser & " and " & mypass
set theuser to paragraphs of "ahole45\nbart33\npiemyeye\nyeahme1\nyoufailed4"¨
set thepass to paragraphs of "mypass663\nlisawmarge\nfound25\nyourmom2u\n2rich4u"
set thelist to {}
set userCount to (count theuser)
if userCount = (count thepass) then
repeat with numb from 1 to userCount
set user to item numb of theuser
set pass to item numb of thepass
set end of thelist to {name:user, password:pass}
end repeat
else
error "The number of usernames in not equal to the number of passwords." number -1 from {theuser} & {thepass}
end if
set myuser to name of item 3 of thelist
set mypass to password of item 3 of thelist
display dialog myuser & " and " & mypass
set theuser to paragraphs of "ahole45\nbart33\npiemyeye\nyeahme1\nyoufailed4\nyourmom\nvidgame99"
set thepass to paragraphs of "mypass663\nlisawmarge\nfound25\nyourmom2u\n2rich4u\nmewiththat\ndoin'yourmom"
set thelist to {}
if (count theuser) = (count thepass) then
repeat with numb from 1 to (count theuser) - 1
set user to item numb of theuser
set pass to item numb of thepass
set end of thelist to {name:user, password:pass}
end repeat
else
error "The number of usernames in not equal to the number of passwords." number 0 from {theuser} & {thepass}
end if
set numb to 0
set numblist to {}
repeat (count theuser) times
set numb to numb + 1
set user to item numb of theuser
set numblist to numblist & ((numb & " >" & user & "<") as string)
end repeat
set numb to (choose from list numblist) as string
if numb is not "false" then
set myuser to name of item (item 1 of characters of numb) of thelist
set mypass to password of item (item 1 of characters of numb) of thelist
display dialog myuser & " and " & mypass
end if
set theuser to paragraphs of "ahole45\nbart33\npiemyeye\nyeahme1\nyoufailed4\nyourmom\nvidgame99"
set thepass to paragraphs of "mypass663\nlisawmarge\nfound25\nyourmom2u\n2rich4u\nmewiththat\ndoin'yourmom"
set thelist to {}
if (count theuser) = (count thepass) then
repeat with numb from 1 to (count theuser)
set user to item numb of theuser
set pass to item numb of thepass
set end of thelist to {name:user, password:pass}
end repeat
else
error "The number of usernames in not equal to the number of passwords." number 0 from {theuser} & {thepass}
end if
set usernameinput to text returned of (display dialog "Please put your username below." default answer "" buttons {"Continue"} default button 1 with title "Username") as string
set passinput to text returned of (display dialog "Please put your password below." default answer "" buttons {"Login"} default button 1 with title "Password") as string
set numb to 0
repeat with user in theuser
set numb to numb + 1
set user to user as string
if user is usernameinput then
set myuser to {true, numb}
else if user is not usernameinput then
set myuser to {false}
end if
end repeat
if myuser is not {false} then
set mypass to (item (item 2 of myuser as integer) of thepass) as string
if mypass is passinput then
set thelogin to true
else
set thelogin to false
end if
else
return false
end if
An error keeps popping up. The “if” statement seems to be the problem (I used dialogs to show EVERY variable’s content as string). Can someone help me?
You need to exit this repeat when you’ve found a match, otherwise it’ll just keep going through to the end of the list and always return ‘{false}’ (unless the last item is the match).
set numb to 0
set myuser to {false}
repeat with user in theuser
set numb to numb + 1
set user to user as string
if user is usernameinput then
set myuser to {true, numb}
exit repeat
end if
end repeat
Or, if you’re taking any notice of the code improvements I gave you yesterday:
set myuser to {false}
repeat with numb from 1 to userCount
set user to item numb of theuser
if user is usernameinput then
set myuser to {true, numb}
exit repeat
end if
end repeat
Or, if you want to use the list of records you’ve just created, replace all of this .
. with this:
set thelogin to ({{name:usernameinput, password:passinput}} is in thelist)