Guest User

Untitled

a guest
Jan 25th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.86 KB | None | 0 0
  1. local function readN(len, replaceChar)
  2. len = len or 12
  3. local input=""
  4. local key = 0
  5. term.setCursorBlink(true)
  6. repeat
  7. local e,p1 = os.pullEvent()
  8. if e=="char" then
  9. if #input < len then
  10. input = input .. p1
  11. term.write(replaceChar or p1)
  12. end
  13. elseif e=="key" and p1==keys.backspace and #input > 0 then
  14. input = input:sub(1,#input-1)
  15. local x,y = term.getCursorPos()
  16. term.setCursorPos(x-1,y)
  17. term.write(" ")
  18. term.setCursorPos(x-1,y)
  19. end
  20. until p1==keys.enter
  21. term.setCursorBlink(false)
  22. return input
  23. end
  24.  
  25. sid = 0
  26. lockdown = 0
  27. actc = ""
  28. actpw = ""
  29. actpc = ""
  30. userlog = ""
  31. userpas = ""
  32. puselog = ""
  33. prog = 0
  34.  
  35. function clear()
  36. term.clear()
  37. term.setCursorPos(1,1)
  38. end
  39.  
  40. function menu(id, text)
  41. if sid == id then
  42. write">> "
  43. else
  44. write" "
  45. end
  46. print(text)
  47. end
  48.  
  49. if not fs.exists("pending") then
  50. shell.run("mkdir pending")
  51. if not fs.exists("users") then
  52. shell.run("mkdir users")
  53. else
  54. end
  55. elseif not fs.exists("users") then
  56. shell.run("mkdir users")
  57. end
  58.  
  59. clear()
  60. while prog == 0 do
  61. --os.pullEvent = os.pullEventRaw
  62. rep1 = 0
  63. rep2 = 0
  64. rep3 = 0
  65. rep4 = 0
  66. rep5 = 0
  67. rep6 = 0
  68. ioerror = 0
  69. term.setCursorPos(1, 12)
  70. term.clearLine()
  71. term.setCursorPos(1, 13)
  72. term.clearLine()
  73. term.setCursorPos(1, 14)
  74. term.clearLine()
  75. term.setCursorPos(1, 15)
  76. term.clearLine()
  77. term.setCursorPos(1, 16)
  78. term.clearLine()
  79. term.setCursorPos(1, 17)
  80. term.clearLine()
  81. term.setCursorPos(1,1)
  82. print("|################################################|")
  83. print("| BOUTECH SYSTEM LOGIN |")
  84. print("| OS Version : 1.3 |")
  85. print("|################################################|")
  86. term.setCursorPos(13,7)
  87. print("|------------------------|")
  88. term.setCursorPos(13,8)
  89. print("| |")
  90. term.setCursorPos(13,9)
  91. print("| |")
  92. term.setCursorPos(13,10)
  93. print("| |")
  94. term.setCursorPos(13,11)
  95. print("|------------------------|")
  96. term.setCursorPos(16,8)
  97. menu(0, "Login")
  98. term.setCursorPos(16,9)
  99. menu(1, "Create Account")
  100. term.setCursorPos(16,10)
  101. menu(2, "Shutdown")
  102. event, key = os.pullEvent("key")
  103.  
  104. if key == 200 then
  105. if sid == 0 then
  106. sid = sid+2
  107. elseif sid == 1 then
  108. sid = sid-1
  109. elseif sid == 2 then
  110. sid = sid-1
  111. end
  112. elseif key == 208 then
  113. if sid == 2 then
  114. sid = sid-2
  115. elseif sid == 1 then
  116. sid = sid+1
  117. elseif sid == 0 then
  118. sid = sid+1
  119. end
  120. elseif key == 28 then
  121. if sid == 0 then
  122. term.setCursorPos(13, 12)
  123. print("| Enter Credentials. |")
  124. term.setCursorPos(13, 13)
  125. print("| |")
  126. term.setCursorPos(13, 14)
  127. print("| |")
  128. term.setCursorPos(13, 15)
  129. print("| |")
  130. term.setCursorPos(13, 16)
  131. print("| |")
  132. term.setCursorPos(13, 17)
  133. print("|------------------------|")
  134.  
  135. while rep5 == 0 do
  136. term.setCursorPos(1, 14)
  137. term.clearLine()
  138. term.setCursorPos(1, 16)
  139. term.clearLine()
  140. term.setCursorPos(13, 16)
  141. print("| |")
  142. term.setCursorPos(13, 14)
  143. print("| |")
  144. term.setCursorPos(15, 14)
  145. write("Username: ")
  146. userlog = readN()
  147. if userlog == "adminovrride" then
  148. rnd = math.random(100, 500)
  149. term.setCursorPos(1, 18)
  150. term.clearLine()
  151. term.setCursorPos (17, 18)
  152. print("Override Code: ".. rnd)
  153. apass = tostring((rnd + 11) * 83)
  154. term.setCursorPos(1, 16)
  155. term.clearLine()
  156. term.setCursorPos(13, 16)
  157. print("| |")
  158. term.setCursorPos(15, 16)
  159. write("Password: ")
  160. ovrpass = readN(12, "*")
  161. if ovrpass == apass then
  162. term.setCursorPos(1, 18)
  163. term.clearLine()
  164. term.setCursorPos(15, 18)
  165. print("Override Successful...")
  166. sleep(3)
  167. term.clear()
  168. term.setCursorPos(1, 1)
  169. rep5 = rep5+1
  170. rep6 = rep6+1
  171. prog = prog+1
  172. else
  173. term.setCursorPos(1, 18)
  174. term.clearLine()
  175. term.setCursorPos(15, 18)
  176. print(" Override Failed...")
  177. sleep(1)
  178. rep5 = rep5+1
  179. rep6 = rep6+1
  180. sid = 0
  181. end
  182. else
  183. if userlog == "" then
  184. term.setCursorPos(1, 18)
  185. term.clearLine()
  186. term.setCursorPos(18, 18)
  187. print("Invalid Username")
  188. sleep(1)
  189. ioerror = ioerror+1
  190. if ioerror == 3 then
  191. rep5 = rep5+1
  192. rep6 = rep6+1
  193. sid = 0
  194. else
  195. end
  196. else
  197. ioerror = 0
  198. ulog = fs.exists("users/".. userlog)
  199. if ulog == true then
  200. term.setCursorPos(1, 16)
  201. term.clearLine()
  202. term.setCursorPos(13, 16)
  203. print("| |")
  204. term.setCursorPos(15, 16)
  205. write("Password: ")
  206. userpas = readN(12, "*")
  207. if userpas == "" then
  208. term.setCursorPos(1, 18)
  209. term.clearLine()
  210. term.setCursorPos(15, 18)
  211. print("Invalid Password Entry")
  212. sleep(1)
  213. ioerror = ioerror+1
  214. term.setCursorPos(1, 18)
  215. term.clearLine()
  216. if ioerror == 3 then
  217. rep5 = rep5+1
  218. sid = 0
  219. else
  220. end
  221. else
  222. ulog = io.open("users/".. userlog, "r") or nil
  223. pass = ulog and ulog:read()
  224. ulog:close()
  225. if (pass and pass==userpas) then
  226. term.setCursorPos(1, 18)
  227. term.clearLine()
  228. term.setCursorPos(16, 18)
  229. print(" Login Success...")
  230. currentw = fs.open("current", "w")
  231. accessr = fs.open("users/".. userlog, "r")
  232. accessl = accessr.readLine() and accessr.readLine()
  233. currentw.writeLine(userlog)
  234. currentw.writeLine(accessl)
  235. currentw.close()
  236. accessr.close()
  237. rep5 = rep5+1
  238. rep6 = rep6+1
  239. prog = prog+1
  240. sid = 0
  241. sleep(2)
  242. shell.run("system")
  243. else
  244. if lockdown < 2 then
  245. term.setCursorPos(1, 18)
  246. term.clearLine()
  247. term.setCursorPos(16, 18)
  248. print(" Wrong Password")
  249. sleep(1)
  250. if userlog == puselog then
  251. lockdown = lockdown+1
  252. else
  253. lockdown = 0
  254. puselog = userlog
  255. lockdown = lockdown+1
  256. end
  257. else
  258. while rep6 == 0 do
  259. term.setCursorPos(15, 18)
  260. rnd = tostring(math.random(101, 999))
  261. if not fs.exists("pending/".. rnd) then
  262. fs.move("users/".. userlog, "pending/".. rnd)
  263. term.setCursorPos(1, 18)
  264. term.clearLine()
  265. term.setCursorPos(15, 18)
  266. print(" Lockdown Ref #: "..rnd)
  267. sleep(1)
  268. ulog = fs.open("pending/".. rnd, "a")
  269. ulog.writeLine("Username: ".. userlog)
  270. ulog.close()
  271. rep6 = rep6+1
  272. rep5 = rep5+1
  273. sid = 0
  274. else
  275. end
  276. end
  277. end
  278. end
  279. end
  280. else
  281. term.setCursorPos(14, 18)
  282. print(" Bad/Unknown Username")
  283. sleep(1)
  284. end
  285. end
  286. end
  287. end
  288. elseif sid == 1 then
  289. term.setCursorPos(13, 12)
  290. print("| Submit Account Info. |")
  291. term.setCursorPos(13, 13)
  292. print("| |")
  293. term.setCursorPos(13, 14)
  294. print("| |")
  295. term.setCursorPos(13, 15)
  296. print("| |")
  297. term.setCursorPos(13, 16)
  298. print("| |")
  299. term.setCursorPos(13, 17)
  300. print("|------------------------|")
  301.  
  302. while rep1 == 0 do
  303. term.setCursorPos(1, 14)
  304. term.clearLine()
  305. term.setCursorPos(13, 14)
  306. print("| |")
  307. term.setCursorPos(15, 14)
  308. write("Username: ")
  309. input = readN()
  310. actc = input
  311. actex = fs.exists("users/".. actc)
  312. if input == "adminovrride" then
  313. term.setCursorPos(1, 18)
  314. term.clearLine()
  315. term.setCursorPos(18, 18)
  316. print("Invalid Username")
  317. sleep(1)
  318. ioerror = ioerror+1
  319. if ioerror == 3 then
  320. rep1 = 1
  321. rep2 = 1
  322. rep3 = 1
  323. sid = 0
  324. else
  325. end
  326. else
  327. if input == "" then
  328. term.setCursorPos(1, 18)
  329. term.clearLine()
  330. term.setCursorPos(18, 18)
  331. print("Invalid Username")
  332. sleep(1)
  333. ioerror = ioerror+1
  334. if ioerror == 3 then
  335. rep1 = 1
  336. rep2 = 1
  337. rep3 = 1
  338. sid = 0
  339. else
  340. end
  341. elseif actex == true then
  342. term.setCursorPos(1, 18)
  343. term.clearLine()
  344. term.setCursorPos(15, 18)
  345. print (" Username Unavailable")
  346. sleep(1)
  347. else
  348. ioerror = 0
  349. rep1 = 1
  350. end
  351. end
  352. end
  353.  
  354. while rep2 == 0 do
  355. while rep3 == 0 do
  356. term.setCursorPos(15, 15)
  357. write("Password: ")
  358. input = readN(12, "*")
  359. if input == "" then
  360. term.setCursorPos(1, 18)
  361. term.clearLine()
  362. term.setCursorPos(15, 18)
  363. print("Invalid Password Entry")
  364. sleep(1)
  365. ioerror = ioerror+1
  366. if ioerror == 3 then
  367. rep1 = 1
  368. rep2 = 1
  369. rep3 = 1
  370. else
  371. end
  372. else
  373. ioerror = 0
  374. actpw = input
  375. rep3 = 1
  376. rep2 = 1
  377. end
  378. end
  379.  
  380. term.setCursorPos(13, 16)
  381. print("| |")
  382. term.setCursorPos(15, 16)
  383. write("Confirm : ")
  384. input = readN(12, "*")
  385. actpc = input
  386. if (actpc) == (actpw) then
  387. while rep4 == 0 do
  388. rnd = tostring(math.random(1011, 9999))
  389. if not fs.exists("pending/".. rnd) then
  390. file = fs.open("pending/".. rnd, "w")
  391. file.writeLine(actc)
  392. file.writeLine(actpw)
  393. file.close()
  394. rep4 = rep4+1
  395. else
  396. end
  397. end
  398. term.setCursorPos(1, 18)
  399. term.clearLine()
  400. term.setCursorPos(13, 18)
  401. print(" Pending... Ref #: ", rnd)
  402. sleep(1)
  403. ioerror = 0
  404. rep2 = 1
  405. sid = 0
  406. else
  407. term.setCursorPos(1, 18)
  408. term.clearLine()
  409. term.setCursorPos(15, 18)
  410. print("Password Doesn't Match")
  411. sleep(1)
  412. rep2 = 0
  413. ioerror = ioerror+1
  414. if ioerror == 3 then
  415. rep1 = 1
  416. rep2 = 1
  417. rep3 = 1
  418. else
  419. end
  420. end
  421. end
  422.  
  423. elseif sid == 2 then
  424. term.setCursorPos(13,14)
  425. print("|########################|")
  426. term.setCursorPos(13,15)
  427. print("# SYSTEM SHUTTING DOWN!! #")
  428. term.setCursorPos(13,16)
  429. print("|########################|")
  430. sleep(3)
  431. os.shutdown()
  432. end
  433. end
  434. end
Add Comment
Please, Sign In to add comment