Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- loginTable = {
- {username="the cat", pw="password"},
- {username="example", pw="example"},
- }
- letters = {"A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", " ", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y", "Z", "z", "_"}
- usernameLetters = {}
- function breakString() -- This Breaks up the string the userenters so it can be compard induvidually
- for i = 1, username:len() do
- table.insert(usernameLetters, username:sub(i, i))
- end
- end
- function welcome() -- This compares the strings from letters with the username that was entered by the user
- breakString()
- term.clear()
- term.setCursorPos(1, 1)
- write("Welcome:")
- for userNum = 1, #username do
- for i = 1, #letters do
- term.setCursorPos(9+userNum, 1)
- if letters[i] == usernameLetters[userNum] then
- write(letters[i])
- break
- else
- write(letters[i])
- end
- os.sleep(0.001)
- end
- end
- end
- function printLine(bgColour, fgColour, x, y, length, text) -- This is used to print the text with the coloured box to the right of it example: printLine(colors.green, colors.red, 10, 4, 12, "Username:")
- term.setBackgroundColour(colors.black)
- term.setTextColour(fgColour)
- term.setCursorPos(x, y)
- for i = 0, length do
- term.setBackgroundColour(bgColour)
- write(" ")
- end
- term.setBackgroundColour(colors.black)
- term.setCursorPos(x-#text, y)
- write(text)
- end
- function readInput(bgColour, fgColour, x, y, inRead) -- This is simply a read() but with background and forground color
- term.setBackgroundColour(bgColour)
- term.setTextColour(fgColour)
- term.setCursorPos(x, y)
- local input = read(inRead)
- term.setBackgroundColour(colors.black)
- return input
- end
- function login()
- repeat
- isCorrect = false
- term.clear()
- term.setBackgroundColour(colors.black)
- term.setCursorPos(1,1)
- printLine(colors.green, colors.red, usernameX, usernameY, 14, "Username:")
- printLine(colors.green, colors.red, passwordX, passwordY, 14, "Password:")
- username = readInput(colors.green, colors.red, usernameX, usernameY)
- password = readInput(colors.green, colors.red, passwordX, passwordY, "*")
- for i = 1, #loginTable do
- if loginTable[i].username == username and loginTable[i].pw == password then
- isCorrect = true
- end
- end
- until isCorrect
- end
- function loading()
- --Enter here for loading feel free to change what its currently doing
- for i = 0, 100 do
- term.clear()
- term.setCursorPos(1,1)
- print("Loading: "..i.."%")
- os.sleep(.1)
- end
- end
- -- [[ Change these values to change the pos of the login screen (mess around with the values to see what happens) ]]
- usernameX = 20
- usernameY = 5
- passwordX = 20
- passwordY = 7
- term.clear()
- login() -- calling login method
- loading() --if you want loading so after the login you can write loading: 20% going up so on then when it ends it will do the welcome scrolling text
- welcome() -- welcomes the user (scrolls through text)
- term.setCursorPos(1,10)
Advertisement
Add Comment
Please, Sign In to add comment