Advertisement
spexiono

XLogin

Mar 29th, 2013
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.85 KB | None | 0 0
  1. local version = "XLogin V 1.8"
  2. --Login program by Spexiono
  3. --GNU GENERAL PUBLIC LICENSE
  4. os.pullEvent = os.pullEventRaw  --Prevent Terminate
  5. term.clear()
  6. term.setCursorPos(1,1) --Prepare terminal
  7. --User details----------------
  8. local user = "name"         --Remember, your login is CasE sEnsaTivE
  9. local password = "1234"     --
  10. --Configuration --------------
  11. local enable_modem = true   --Enable modem auto-setup
  12. local enable_id = true      --Show ID
  13. local enable_label = true   --Show Label
  14. local enable_welcome = true --Show welcome after login
  15. ------------------------------
  16. local w, h = term.getSize()
  17.  
  18. --Functions
  19. local function tcolor(cval) --Changes text color IF advanced computer
  20.     if term.isColor() then
  21.         term.setTextColor(colors[cval])
  22.     end
  23. end
  24.  
  25. local function indentprint(text) --Prints text and sets cursor to next line at same X pos
  26.         local curx,cury = term.getCursorPos()
  27.         term.write(text)
  28.         term.setCursorPos(curx,cury+1)
  29. end
  30.  
  31. --Thanks to BigSHinyToys for this modem scanner function
  32. local function openRednet()
  33.     for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do
  34.         if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  35.             rednet.open(side)
  36.             return true
  37.         end
  38.     end
  39. end
  40.  
  41. ------------
  42. if w < 51 or h < 19 then --The GUI only supports the default computer terminal
  43.     tcolor("red")
  44.     print(version," is running in Safe mode!")
  45.     tcolor("white")
  46.     while true do
  47.         write("Username:") u = read()
  48.         write("Password:") p = read("*")
  49.         if u == user and p == password then
  50.             print("Welcome "..user)
  51.             error()
  52.         else
  53.             tcolor("red")
  54.             print("Wrong Login")
  55.             tcolor("white")
  56.         end
  57.     end
  58. end
  59.  
  60. --Print the login screen
  61. tcolor("blue")
  62. print[[
  63.  
  64.     +------------------------------------------+
  65.     |                                          |
  66.     |                                          |
  67.     |                                          |
  68.     |                                          |
  69.     |           +------------------+           |
  70.     |           |                  |           |
  71.     |           +------------------+           |
  72.     |                                          |
  73.     |           +------------------+           |
  74.     |           |                  |           |
  75.     |           +------------------+           |
  76.     |                                          |
  77.     |                                          |
  78.     |                                          |
  79.     |                                          |
  80.     +------------------------------------------+]]
  81.  
  82. --Center version + title
  83. term.setCursorPos(w/2-version:len()/2,5)
  84. tcolor("yellow")
  85. print(version)
  86. tcolor("white")
  87.  
  88. if enable_id == true then
  89.     term.setCursorPos(24,16)
  90.     write("ID:") tcolor("lime") write(os.getComputerID())
  91. end
  92.  
  93. if enable_label == true then
  94.     term.setCursorPos(8,3)
  95.     if os.getComputerLabel() ~= nil then
  96.         tcolor("white")
  97.         write("Label:") tcolor("lime") write(os.getComputerLabel())
  98.     else
  99.         tcolor("gray")
  100.         write("Label")
  101.     end
  102. end
  103.  
  104. tcolor("white")
  105.  
  106. if enable_modem == true then
  107.     term.setCursorPos(8,16)
  108.     if openRednet() then
  109.         write("Modem:")
  110.         tcolor("lime")
  111.         print("enabled")
  112.     else
  113.         tcolor("gray")
  114.         print("Modem")
  115.     end
  116. end
  117.  
  118. tcolor("white")
  119. --Start main loop
  120. while true do
  121.     term.setCursorPos(9,8)
  122.     print("Username")
  123.     term.setCursorPos(9,12)
  124.     print("Password")
  125.     --Read username and password inputs
  126.     term.setCursorPos(18,8)
  127.     u = read()
  128.     term.setCursorPos(18,12)
  129.     p = read("*")
  130.     if p == password and u == user then
  131.         --successful
  132.         term.clear()
  133.         term.setCursorPos(1,1)
  134.     if enable_welcome == false then --Hide Welcome screen
  135.         error() --End program now
  136.     else
  137.         --Expanding GUI
  138.         tcolor("blue")
  139.         print[[
  140.     +------------------------------------------+
  141.     |                                          |
  142.     |                                          |
  143.     |                                          |]]
  144.         term.setCursorPos(7,2)
  145.         tcolor("yellow")
  146.         print(version)
  147.         tcolor("white")
  148.         term.setCursorPos(11+version:len(),2)
  149.         print("Welcome ", u ,"!")
  150.         --Reprint enabled modules (Modem-id-label)
  151.         if enable_modem == true then
  152.             term.setCursorPos(8,3)
  153.             if openRednet() then
  154.                 write("Modem:")
  155.                 tcolor("lime")
  156.                 print("enabled")
  157.             else
  158.                 tcolor("gray")
  159.                 write("Modem")
  160.             end
  161.         end
  162.         if enable_id == true then
  163.             term.setCursorPos(24,3)
  164.             tcolor("white")
  165.             write("ID:") tcolor("lime") print(os.getComputerID())
  166.         end
  167.         if enable_label == true then
  168.             term.setCursorPos(8,4)
  169.             if os.getComputerLabel() ~= nil then
  170.                 tcolor("white")
  171.                 write("Label:") tcolor("lime") print(os.getComputerLabel())
  172.             else
  173.                 tcolor("gray")
  174.                 print("Label")
  175.             end
  176.         end
  177.  
  178.         --Check if login details are defaults then extend the box and notify if true
  179.         tcolor("blue")
  180.         if u == "name" and p == "1234" then
  181.             term.setCursorPos(1,5)
  182.             print("    |                                          |")
  183.             print("    |                                          |")
  184.             print("    +------------------------------------------+")
  185.             tcolor("red")
  186.             term.setCursorPos(11,5)
  187.             print("Warning! Default username!")
  188.             term.setCursorPos(11,6)
  189.             print("Warning! Default password!")
  190.             term.setCursorPos(1,8)
  191.         elseif p == "1234" then
  192.             term.setCursorPos(1,5)
  193.             print("    |                                          |")
  194.             tcolor("red")
  195.             term.setCursorPos(11,5)
  196.             print("Warning! Default password!")
  197.             tcolor("blue")
  198.             print("    +------------------------------------------+")
  199.         elseif u == "name" then
  200.             term.setCursorPos(1,5)
  201.             tcolor("blue")
  202.             print("    |                                          |")
  203.             tcolor("red")
  204.             term.setCursorPos(11,5)
  205.             print("Warning! Default username!")
  206.             tcolor("blue")
  207.             print("    +------------------------------------------+")
  208.         else
  209.             tcolor("blue")
  210.             term.setCursorPos(1,5)
  211.             print("    +------------------------------------------+")
  212.         end
  213.         tcolor("white")
  214.         error() --End program--
  215.     end
  216.  
  217.     else    --Authentication was unsuccessful
  218.         --Highlights which input was empty
  219.         tcolor("red")
  220.         term.setCursorPos(12,14)
  221.         print("Incorrect username or password")
  222.         tcolor("blue")
  223.         term.setCursorPos(17,7)
  224.         indentprint("+------------------+")--Redraw username box
  225.         indentprint("|                  |")
  226.         indentprint("+------------------+")
  227.         term.setCursorPos(17,11)
  228.         indentprint("+------------------+")--Redraw password box
  229.         indentprint("|                  |")
  230.         indentprint("+------------------+")
  231.         tcolor("red")
  232.         if u == "" then
  233.             term.setCursorPos(17,7)
  234.             indentprint("#------------------#")
  235.             indentprint("|                  |")
  236.             indentprint("#------------------#")
  237.         end
  238.         if p == "" then
  239.             term.setCursorPos(17,11)
  240.             indentprint("#------------------#")
  241.             indentprint("|                  |")
  242.             indentprint("#------------------#")
  243.         end
  244.         tcolor("white")
  245.     end
  246. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement