/* VER: Terminus 2.0 - host.scp (04.06.92) */

   cls
   print "Terminus Host script"
   gosub get_user   
   end

get_user:
   close #1
   print
   input "First name: ", firstname$
   input " Last name: ", lastname$

   firstname$ = trim$(upper$(firstname$))
   lastname$ = trim$(upper$(lastname$))

   if exists("terminus:host.users")
      open input 1, "terminus:host.users"
   else
      goto reenter_city
   endif

find_user_loop:
   read #1, user_firstname$

   if user_firstname$ == "END_OF_FILE" 
      close #1
      print
      ask "Name not found, [R]eenter or [C]ontinue? ", a$
      print
      a$ = trim$(upper$(a$))

      if a$ == "R"
         goto get_user
      endif

reenter_city:
      input "      City: ", city$
      city$ = trim$(upper$(city$))

      if not len(city$)
         print "Please enter the city you're from..."
         goto reenter_city
      endif

reenter_state:
      input "     State: ", state$
      state$ = trim$(upper$(state$))

      if not len(state$)
         print "Please enter the state you're from..."
         goto reenter_state
      endif

reenter_password:
      input quiet "Enter password to use on this system: ", password$
      password$ = trim$(upper$(password$))

      if not len(password$)
         print "You MUST enter a password for use on this system!"
         goto reenter_password
      endif

      input quiet "Reenter password to verify: ", user_password$
      user_password$ = trim$(upper$(user_password$))
      
      if password$ != user_password$
         goto reenter_password 
      endif

      user_security = 10
      gosub add_user
      goto hello
   else
      read #1, user_lastname$, user_city$, user_state$, user_password$, user_security

      if user_firstname$ == firstname$
         if user_lastname$ == lastname$
            print "From "; user_city$; ","; user_state$;
            ask " [Y]/n? ", i$
            print
            if trim$(upper$(i$)) == "N"
               goto get_user
            else
               i = 1
password_loop:
               input quiet "  Password: ", password$
               password$ = trim$(upper$(password$))

               if user_password$ != password$
                  if i == 3
                     print "Password attempts exceeded, goodbye."
                     goto done
                  endif

                  i = i + 1
                  goto password_loop
               endif
hello:
               print "Welcome "; firstname$; " "; lastname$; " to the Terminus Host!"
               print "Your current security level is: "; user_security
               goto done
            endif
         endif
      endif
   endif
   goto find_user_loop               
   
done:
   close #1
   return
      
add_user:                          
   open append 1, "terminus:host.users"
   write #1, firstname$, lastname$, city$, state$, password$, user_security
   close #1
   return
