I added a line in repeat to retry connecting until it gets the password prompt:
I don't see the point in doing this. Either you're going to connect or you're not. If you're not then the problem is a general network problem (e.g. you can't get to the router from where you are), so trying multiple times isn't going to make that any more likely. There's no harm in doing it, I guess, but it doesn't add any extra value to the script.
Can't we without "front window" so the process is not interrupted by other apps?
Yes - what you have to do is keep track of the window the first command is issued in.
What I tend to do is issue the first command without a target window (this opens a new window), then I grab that window's ID and use it as the target for all future commands. e.g.:
tell application "Terminal"
do script "telnet 192.168.1.1" -- this opens a new window
set wID to ID of front window -- grab the new window's ID
repeat until (last word of (contents of window id wID as text) = "password")
delay 1
end repeat
do script "mypassword" in window id wID
...
In this way you can do whatever you like - switch windows, open new ones, etc. and the script will still target the right one (as long as you don't close that, of course).
...but I'm not sure how to set a timeout of say 120 secs?
I assume you mean for the initial connection? Just keep a counter of how many times you've iterated through the repeat loop:
...
set loopCount to 0
repeat until (last word of (contents of window id wID as text) = "password")
set loopCount to loopCount + 1 -- increment the counter
if loopCount = 120 then error -128 -- if we've been here 120 times, cancel the script execution
delay 1
end repeat