Advertisement
Guest User

accountapi

a guest
Jan 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. -- This is the accounts API
  2. -- I made this so that my brain doesn't hurt
  3. -- Chock500 - 22|12|12,016HE
  4.  
  5. os.loadAPI("chockos/fileapi")
  6.  
  7. function checkAccountsFile()
  8.   -- this just makes sure that the accounts file
  9.   -- does exists to avoid errors
  10.   if fs.exists("chockos/accounts") then
  11.     return true
  12.   else
  13.     fs.makeDir("chockos/accounts")
  14.     return false
  15.   end
  16. end
  17.  
  18. function addUser(name,pass)
  19.   checkAccountsFile()
  20.   if fs.exists("chockos/accounts/"..name) then
  21.     return false
  22.   else
  23.     fs.makeDir("chockos/accounts/"..name)
  24.     fs.makeDir("chockos/accounts/"..name.."/fs")
  25.     fileapi.writeFile("chockos/accounts/"..name,"pass",pass)
  26.     return true
  27.   end
  28. end
  29.  
  30. function removeUser(name,pass)
  31.   -- this removes a user, but only if the password
  32.   -- is known
  33.   checkAccountsFile()
  34.   if fs.exists("chockos/accounts/"..name) then
  35.     if fileapi.readFile("chockos/accounts/"..name.."/pass") == pass then
  36.       fs.delete("chockos/accounts/"..name)
  37.       return true
  38.     else
  39.       return false
  40.     end
  41.   else
  42.     return false
  43.   end
  44. end
  45.  
  46. function signIn(name,pass)
  47.   -- checks the typed in password against the one
  48.   -- written down in the file
  49.   checkAccountsFile()
  50.   if fs.exists("chockos/accounts/"..name) then
  51.     if fileapi.readFile("chockos/accounts/"..name.."/pass") == pass then
  52.       return true
  53.     else
  54.       return false
  55.     end
  56.   else
  57.     return false
  58.   end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement