home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / nrxsamp.zip / REG2.NRX < prev    next >
Text File  |  1997-08-13  |  2KB  |  77 lines

  1. /*
  2.  * REG2.nrx  --  accept and validate registration for access
  3.  *                    to private data
  4.  *
  5.  */
  6.  
  7. class REG2
  8.  
  9.   properties private static
  10.   UserList = ''                             -- valid user names array
  11.   NewUser = ''                              -- new user's userid
  12.  
  13. method main(s=String[]) static
  14.  
  15.   UserList['mickey'] = 'ClubLeader'         -- initialize some registered
  16.   UserList['minnie'] = 'mouseketeer'        --  users
  17.   UserList['donald'] = 'aDuck'
  18.  
  19.   loop forever
  20.      ThisUser = GetUser                     -- get this user's information
  21.      if ThisUser.left(1) = 'q' then leave   -- user wants out
  22.      if ThisUser.left(3) = 'new'            -- if new, sign them up
  23.         then do
  24.            Register
  25.            ThisUser = NewUser
  26.            end
  27.      if Validate(ThisUser)                  -- validate this user
  28.         then say "Access OK'd"              -- let them in if OK
  29.         else say "Access denied"
  30.      end
  31.  
  32.  
  33. /* Get user sign-on information */
  34.  
  35. method GetUser static
  36.  
  37.   id = ''
  38.   pw = ''
  39.   say 'Userid ("new" to register; "q" to exit):'
  40.   id = ask
  41.   if id \= 'new' & id \= 'q' then do
  42.      say 'Password:'
  43.      pw = ask
  44.      end
  45.   return id'.'pw
  46.  
  47.  
  48. /* Register a new user  */
  49.  
  50. method Register static
  51.  
  52.   say 'Choose a userid (it cannot be "new"):' -- prompt for userid
  53.   NewUser = ask
  54.   say 'Choose a password:'                    -- and password
  55.   pw1 = ask
  56.   say 'Re-enter password to verify:'
  57.   loop forever                                -- loop until password
  58.      pw2 = ask                                --   verified
  59.      if pw2 == pw1 then leave                 -- case-sensitive compare
  60.      say 'Verification failed; re-enter password'
  61.      end
  62.   UserList[NewUser] = pw1                     -- add to "valid names" array
  63.   NewUser = NewUser'.'pw1
  64.   say 'Registration complete'
  65.   return
  66.  
  67.  
  68. /* Validate a userid/password   */
  69.  
  70. method Validate(userid) static returns boolean
  71.  
  72.   parse userid id '.' pw
  73.   if UserList[id] \== pw then return 0        -- case-sensitive compare
  74.      else return 1
  75.  
  76.  
  77.