Try this commented version, maybe it will point things out:
Code:

On *:start:{
  ;
  ; Please note: I changed the event from on Load to on Start.
  ;
  socklisten telnet 4445
}
 
On *:socklisten:telnet:{
  ;
  ; If there was an error, stop the script.
  ; (I always check $sockerr on Socklisten and Sockopen).
  ;
  if $sockerr { return }
  ;
  ; Assign the incoming connection a temporary name
  ; then grab its IP address, store it in a local variable
  ; and rename the socket the IP address.
  ;
  sockaccept temp
  var %sockname = $sock(temp).ip
  sockrename temp %sockname
  ;
  ; Welcome the user
  ;
  echo -se * Telnet Session Initiated from %sockname
  sockwrite -tn %sockname MessageBot Telnet Console Version 1.0 Copyright 2002-2003 MessageBot.net
  sockwrite -tn %sockname ========================================================================
  sockwrite -tn %sockname Please login below
  sockwrite -tn %sockname Username:
}
 
On *:sockread:?*.?*.?*.?*:{
  var %data
  sockread %data
  if !%data { return }
  var %mark = $sock($sockname).mark, %user = $gettok(%mark,1,32), %pass = $gettok(%mark,2,32) 
  tokenize 32 %data
  ;
  if !%pass {
    if !%user {
      ;
      ; Set username.
      ;
      sockwrite -tn $sockname Sent username ' $+ $1 $+ '
      sockwrite -tn $sockname Password:
      sockmark $sockname $1
      return
    }
    ;
    ; Verify password
    ;
    if $1 != $gettok($hget(nicks,%user),1,32) {
      sockwrite -tn $sockname Invalid password, bye.
      sockclose $sockname
      return
    }
    ;
    ; Accept user logon.
    ;
    sockwrite -tn $sockname Password accepted for %user
    sockmark $sockname %user $1
    return
  }
  ;
  ; Your stuff goes here. Info you can retrieve:
  ;
  ;   User:    %user
  ;   Pass:    %pass
  ;   IP:      $sockname
  ;   Command: $1-        
  ;
}