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