Advertisement
Guest User

Untitled

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