Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("this computer ID is "..os.getComputerID())
- sleep(0.1)
- print("-------------------------------")
- print("this server cant do any thing, but it save the username and password")
- print("changelog")
- print("CURRENT:")
- print("v0.3.4 - Security question!")
- print("--------------------------------------------")
- print("v0.3.3 - Updated, you dont need testsave()")
- print("v0.3.2 - added Nick checking")
- print("v0.3 - NICKNAME!")
- print("v0.2 - allow to change username & password")
- print("v0.1 - Published")
- print("--------------------------------------------")
- print("Pre-Pre-Alpla version")
- print("v0.05 - fixed some bug")
- print("v0.01 - born")
- function load(name)
- if not fs.exists(name) then
- local file = fs.open(name,"a")
- local teh = {"test", "test"}
- file.write(textutils.serialize(teh))
- file.close()
- return textutils.unserialize(sContents)
- else
- local file = fs.open(name,"r")
- local sContents = file.readAll()
- file.close()
- return textutils.unserialize(sContents)
- end
- end
- function adds(ID, tContents)
- rednet.send(ID, "qdone")
- fs.delete("security.txt")
- local file = fs.open("security.txt","a")
- file.write(textutils.serialize(tContents))
- file.close()
- end
- function se(username, question, password)
- local ID, MSG, DISTANCE = rednet.receive(10)
- if MSG == "could" then
- local tContents = load("security.txt")
- if tContents[1] == "test" and tContents[1] == "test" then
- table.remove(tContents, 3)
- table.remove(tContents, 2)
- table.remove(tContents, 1)
- table.insert(tContents, username)
- table.insert(tContents, question)
- table.insert(tContents, password)
- adds(ID, tContents)
- else
- local i = 1
- repeat
- if username == tContents[i] then
- local o = i + 1
- local n = o + 1
- table.remove(tContents, n)
- table.remove(tContents, o)
- table.insert(tContents, o, question)
- table.insert(tContents, n, password)
- adds(ID, tContents)
- does = "no"
- elseif tConetents[i] == nil or tConetents[i] == "" then
- table.insert(tContents, username)
- table.insert(tContents, question)
- table.insert(tContents, password)
- adds(ID, tContents)
- does = "no"
- else
- i = i + 3
- end
- until does == "no"
- does = "yes"
- end
- end
- end
- function nickadd(username, nick)
- local test = load("nick.txt")
- if test[1] == "test" and test[2] == "test" then
- table.remove(test, 2)
- table.remove(test, 1)
- table.insert(test, username)
- table.insert(test, nick)
- else
- table.insert(test, username)
- table.insert(test, nick)
- end
- fs.delete("nick.txt")
- local file = fs.open("nick.txt","a")
- file.write(textutils.serialize(test))
- file.close()
- end
- function nickedit(i, nick)
- local test = load("nick.txt")
- table.remove(test, i)
- table.insert(test, i, nick)
- fs.delete("nick.txt")
- local file = fs.open("nick.txt","a")
- file.write(textutils.serialize(test))
- file.close()
- end
- function nickn(username, nick)
- local ID, MSG, DISTANCE = rednet.receive(10)
- if MSG == "could" then
- tContents = load("nick.txt")
- local i = 2
- repeat
- if nick == tContents[i] then
- rednet.send(ID, "non")
- does = "no"
- elseif tContents[i] == nil or tContents[i] == "" then
- rednet.send(ID, "finishn")
- local o = 1
- repeat
- if username == tContents[o] then
- n = o+1
- nickedit(n, nick)
- does = "no"
- does2 = "no"
- elseif tContents[o] == nil or tContents[o] == "" then
- nickadd(username, nick)
- does = "no"
- does2 = "no"
- else
- o = o + 2
- end
- until does2 == "no"
- does2 = "yes"
- else
- i = i + 2
- end
- until does == "no"
- does = "yes"
- end
- end
- function nickc(username)
- local ID, MSG, DISTANCE = rednet.receive(10)
- if MSG == "could" then
- tContents = load("nick.txt")
- i = 1
- repeat
- if username == tContents[i] then
- local this = load("nick.txt")
- n = i + 1
- rednet.send(ID, "yes")
- rednet.send(ID, this[n])
- does = "no"
- elseif tContents[i] == nil or tContents[i] == "" then
- rednet.send(ID, "nope")
- does = "no"
- else
- i = i + 2
- end
- until does == "no"
- does = "yes"
- end
- end
- function edit(i, txt)
- local test = load("user.txt")
- table.remove(test, i)
- table.insert(test, i, txt)
- fs.delete("user.txt")
- local file = fs.open("user.txt","a")
- file.write(textutils.serialize(test))
- file.close()
- end
- function save(username, password)
- local test
- test = load("user.txt")
- if test[i] == "test" and test[2] == "test" then
- table.remove(test, 2)
- table.remove(test, 1)
- table.insert(test, username)
- table.insert(test, password)
- else
- table.insert(test, username)
- table.insert(test, password)
- end
- fs.delete("user.txt")
- local file = fs.open("user.txt","a")
- file.write(textutils.serialize(test))
- file.close()
- end
- function add(username, password)
- local ID, MSG, DISTANCE = rednet.receive(10)
- if MSG == "could" then
- local tContents = load("user.txt")
- local i = 1
- repeat
- if username == tContents[i] then
- rednet.send(ID, "no")
- does = "no"
- elseif tContents[i] == nil or tContents[i] == "" then
- save(username, password)
- rednet.send(ID, "complete")
- does = "no"
- else
- i = i + 2
- end
- until does == "no"
- does = "yes"
- end
- end
- function search(username, password)
- local ID, MSG, DISTANCE = rednet.receive(10)
- if MSG == "could" then
- local tContents = load("user.txt")
- local i = 1
- repeat
- if username == tContents[i] then
- o = i + 1
- if password == tContents[o] then
- if username == "admin" then
- rednet.send(ID, "admin")
- does = "no"
- else
- rednet.send(ID, "correct")
- does = "no"
- end
- else
- rednet.send(ID, "pass")
- does = "no"
- end
- elseif tContents[i] == nil or tContents[i] == "" then
- rednet.send(ID, "wrong")
- does = "no"
- else
- i = i + 2
- end
- until does == "no"
- does = "yes"
- end
- end
- function change(username, password, wordpass)
- local ID, MSG, DISTANCE = rednet.receive(10)
- if MSG == "could" then
- local tContents = load("user.txt")
- local i = 1
- repeat
- if username == tContents[i] then
- o = i + 1
- if password == tContents[o] then
- edit(o, wordpass)
- rednet.send(ID, "finish")
- does = "no"
- else
- rednet.send(ID, "wrongp")
- does = "no"
- end
- else
- i = i + 2
- end
- until does == "no"
- does = "yes"
- end
- end
- function change2(username, nameuser)
- local ID, MSG, DISTANCE = rednet.receive(10)
- if MSG == "could" then
- local tContents = load("user.txt")
- local i = 1
- repeat
- if username == tContents[i] then
- local o = 1
- repeat
- if nameuser == tContents[o] then
- rednet.send(ID, "nou")
- does2 = "no"
- does = "no"
- elseif tContents[o] == nil or tContents[o] == "" then
- edit(i, nameuser)
- rednet.send(ID, "finish")
- does2 = "no"
- does = "no"
- else
- o = o + 2
- end
- until does2 == "no"
- does2 = "yes"
- else
- i = i + 2
- end
- until does == "no"
- does = "yes"
- end
- end
- rednet.open("back")
- local username,password,nameuser,wordpass,nick,question,answer
- while true do
- local ID, MSG, DISTANCE = rednet.receive()
- if MSG == "user" then
- local ID, MSG, DISTANCE = rednet.receive(10)
- username = MSG
- end
- if MSG == "user2" then
- local ID, MSG, DISTANCE = rednet.receive(10)
- nameuser = MSG
- end
- if MSG == "pass" then
- local ID, MSG, DISTANCE = rednet.receive(10)
- password = MSG
- end
- if MSG == "pass2" then
- local ID, MSG, DISTANCE = rednet.receive(10)
- wordpass = MSG
- end
- if MSG == "nick" then
- local ID, MSG, DISTANCE = rednet.receive(10)
- nick = MSG
- end
- if MSG == "ques" then
- local ID, MSG, DISTANCE = rednet.receive(10)
- question = MSG
- end
- if MSG == "ans" then
- local ID, MSG, DISTANCE = rednet.receive(10)
- answer = MSG
- end
- if MSG == "r" then
- add(username, password)
- end
- if MSG == "l" then
- search(username, password)
- end
- if MSG == "cn" then
- change2(username, nameuser)
- end
- if MSG == "cp" then
- change(username, password, wordpass)
- end
- if MSG == "nc" then
- nickn(username, nick)
- end
- if MSG == "check" then
- nickc(username)
- end
- if MSG == "secur" then
- se(username, question, answer)
- end
- if MSG == "hi" then
- rednet.send(ID, "yes2")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment