AndreSoYeah

login

Nov 22nd, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.91 KB | None | 0 0
  1. --# WaliLogin by Andre A. Walia (walia6)
  2. --# liscensed under CreativeCommons Attribution.
  3. --# You may distribute,remix, tweak, and build
  4. --# upon my work, even commercially, as long as
  5. --# you credit me by my First, middle initial, and last name.
  6. old=os.pullEvent
  7. infoFile=fs.open('accounts','r')
  8. info=textutils.unserialize(infoFile.readAll())
  9. infoFile.close()
  10. bgColor=colors.lightGray -- change this to any color you want
  11. wait=1.5
  12. os.pullEvent=os.pullEventRaw
  13. os.loadAPI("APIS/walCrypt")
  14. os.loadAPI("APIS/sha256")
  15. response = http.get("http://www.pastebin.com/raw.php?i=GQ1JmtNq").readAll()
  16. function invalid(txt,st,col)
  17.   term.setCursorPos(1,1)
  18.   term.setTextColor(col)
  19.   term.setBackgroundColor(colors.blue)
  20.   sX,sY=term.getSize()
  21.   for u=1,sX do
  22.     write(" ")
  23.   end
  24.   term.setCursorPos(st,1)
  25.   write(txt)
  26.   term.setTextColor(colors.black)
  27. end
  28. function updateScreen()
  29.   term.setBackgroundColor(bgColor)
  30.   term.clear()
  31.   --term.setCursorPos(1,1)
  32.   --term.setBackgroundColor(colors.blue)
  33.   --sX,sY=term.getSize()
  34.   --for co=1,sX do
  35.     --write(" ")
  36.   --end
  37.   invalid("Auto-Updater",20,colors.red)
  38.   term.setCursorPos(6,7)
  39.   term.setTextColor(colors.black)
  40.   term.setBackgroundColor(bgColor)
  41.   write("Would you like to update Walia6's Login?")
  42.   --sleep(1)
  43.   term.setCursorPos(11,9)
  44.   term.setBackgroundColor(colors.green)
  45.   term.setTextColor(colors.black)
  46.   write("Okay")
  47.   term.setCursorPos(17,9)
  48.   term.setBackgroundColor(colors.blue)
  49.   write("Don't ask me again")
  50.   term.setCursorPos(37,9)
  51.   term.setBackgroundColor(colors.red)
  52.   write("Nope")
  53.   while true do
  54.     _,b,x,y=os.pullEvent("mouse_click")
  55.     if b==1 then
  56.       if y==9 then
  57.         if x>10 and x<15 then
  58.           if fs.exists("loginSettings/version") then
  59.             hh=fs.open("loginSettings/version","r")
  60.             version = tonumber(hh.readLine())
  61.             hh.close()
  62.           else
  63.             version = 0
  64.           end
  65.             if tonumber(response) > version then
  66.               re=http.get("http://www.pastebin.com/raw.php?i=fJxygMPi").readAll()
  67.               if fs.exists("update") then
  68.                 fs.delete("update")
  69.               end
  70.               hhg=fs.open("update","w")
  71.               hhg.writeLine(re)
  72.               hhg.flush()
  73.               hhg.close()
  74.               term.setTextColor(colors.black)
  75.               term.setBackgroundColor(bgColor)
  76.               term.clear()
  77.               invalid("Notice",23,colors.black)
  78.               term.setCursorPos(9,9)
  79.               term.setTextColor(colors.black)
  80.               term.setBackgroundColor(cgColor)
  81.               write("Please run update after logging in.")
  82.               sleep(3)
  83.               break
  84.             end
  85.           elseif x>16 and x<35 then
  86.           gg=fs.open("loginSettings/noUpdate","w")
  87.           gg.writeLine(" ")
  88.           gg.flush()
  89.           gg.close()
  90.           break
  91.         elseif x>36 and x<41 then
  92.           break
  93.         end
  94.       end
  95.     end
  96.   end
  97.   sleep(3)
  98. end
  99. function main()
  100.   if fs.exists("loginSettings/version") then
  101.     yy=fs.open("loginSettings/version","r")
  102.     vee=yy.readLine()
  103.     yy.close()
  104.     if tonumber(vee) ~= tonumber(response) then
  105.       if not fs.exists("loginSettings/noUpdate") then
  106.         updateScreen()
  107.       end
  108.     end
  109.   else
  110.     if not fs.exists("loginSettings/noUpdate") then
  111.       updateScreen()
  112.     end
  113.   end  
  114.   d=true
  115.   while d do
  116.     term.setBackgroundColor(bgColor)
  117.     term.clear()
  118.     term.setCursorPos(1,1)
  119.     term.setBackgroundColor(colors.blue)
  120.     sX,sY=term.getSize()
  121.     for i=1,sX*2 do
  122.       write(" ")
  123.     end
  124.     term.setCursorPos(19,1)
  125.     term.setTextColor(colors.black)
  126.     print("Please login: ")
  127.     term.setBackgroundColor(bgColor)
  128.     term.setCursorPos(15,9)
  129.     term.setTextColor(colors.blue)
  130.     write("Username: ")
  131.     term.setBackgroundColor(colors.gray)
  132.     write("               ")
  133.     term.setCursorPos(15,11)
  134.     term.setTextColor(colors.blue)
  135.     term.setBackgroundColor(bgColor)
  136.     write("Password: ")
  137.     term.setBackgroundColor(colors.gray)
  138.     write("               ")
  139.     term.setCursorPos(26,9)
  140.     term.setTextColor(colors.cyan)
  141.     inUser = read()
  142.     term.setCursorPos(26,11)
  143.     inPass = read("*")
  144.     if info[inUser] then
  145.       if info[inUser]['hash'] == sha256.sha256(inPass..info[inUser]['salt']) then
  146.         d=false
  147.       else
  148.         invalid("Invalid login",19,colors.red)
  149.         sleep(wait)
  150.       end
  151.     else
  152.       invalid("Invalid login",19,colors.red)
  153.       sleep(wait)
  154.     end
  155.   end
  156.   invalid("Valid login",20,colors.green)
  157.   sleep(wait)
  158.   os.pullEvent = old
  159.   term.setBackgroundColor(colors.black)
  160.   term.setTextColor(colors.white)
  161.   term.clear()
  162.   term.setCursorPos(1,1)
  163.   curUser=inUser
  164.   us=fs.open("loginSettings/curUser","w")
  165.   us.writeLine(curUser)
  166.   us.flush()
  167.   us.close()
  168.   for k,v in pairs(fs.list('APIS/')) do
  169.     os.loadAPI('APIS/'..v)
  170.   end
  171.   shell.run(".shell")    
  172. end
  173. main()
Advertisement
Add Comment
Please, Sign In to add comment