Magus

(Wiremod Expression 2) Lodkagan Library for Logins

Jul 31st, 2012
500
0
Never
12
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.04 KB | None | 0 0
  1. @persist [Username Password Permission]:array
  2. # Library for Loginscreens etc.
  3. # by Magus/Lodkagan
  4.  
  5. # Use the #include "" funxtion.
  6.  
  7. # Functions
  8. #=============================================================================================================
  9. #            addUser(string,string)          - Adds a user, first string is the username, the second is the password,
  10. #                                           *- with the permission number 1 (normal user).
  11. #            addUser(string,string,number)   - Adds a user, first string is the username, the second is the password,
  12. #                                           *- the last number is the permission number.
  13. #  getUserPermission(string)                 - Gets the Permission from the username.
  14. #getUserPermissionID(number)                 - Gets the Permission from the user ID.
  15. #       deleteUserID(number)                 - Delete a user with the ID.
  16. #          getUserID(number)                 - Gets the userID's name.
  17. #        getUserName(string)                 - Gets the Username's ID.
  18. #  getUserIDPassword(number)                 - Gets the userID's Password.
  19. #        getUserList()                       - Returns a list with all Usernames.
  20. #  checkUserPassword(strin,string)           - Checks the Input with the Username and Password.
  21. #                                           *- Returns 0 if Username or/and Password is wrong.
  22. #                                           *- Returns 1 if both is right
  23. #=============================================================================================================
  24.  
  25. function void addUser(UN:string, PW:string) {
  26.     Username:pushString(UN:lower())
  27.     Password:pushString(PW:lower())
  28.     Permission:pushNumber(1)
  29. }
  30.  
  31. function void addUser(UN:string, PW:string, PE:number) {
  32.     Username:pushString(UN:lower())
  33.     Password:pushString(PW:lower())
  34.     Permission:pushNumber(PE)
  35.    
  36. }
  37.  
  38. function number getUserPermission(Name:string) {
  39.     local I = 1
  40.     while((Name:lower() != Username[I,string]) & (Username:exists(I))) {I++}
  41.     if(Username:exists(I)) {return Permission[I,number]}
  42.     else {return 0}
  43. }
  44.  
  45. function number getUserPermissionID(I:number) {
  46.     return Permission[I,number]
  47. }
  48.  
  49. function void deleteUserID(ID:number) {
  50.     Username:remove(ID)
  51.     Password:remove(ID)
  52. }
  53.  
  54. function string getUserIDName(I:number) {
  55.     return Username[I,string]
  56. }
  57.  
  58. function number getUserName(Name:string) {
  59.     local I = 1
  60.    
  61.     while((Name:lower() != Username[I,string]) & (Username:exists(I))) {I++}
  62.     if(Username:exists(I)) {return I}
  63.     else {return 0}
  64. }
  65.  
  66. function string getUserIDPassword(I:number) {
  67.     return Password[I,string]
  68. }
  69.  
  70. function string getUserList() {
  71.     return Username:concat(", ")
  72. }
  73.  
  74. function number checkUserPassword(UN:string, PW:string) {
  75.     local I = 1
  76.    
  77.     while((UN:lower() != Username[I,string]) & (Username:exists(I))) {I++}
  78.    
  79.     if(UN:lower() == Username[I,string]) {
  80.         if(PW:lower() == Password[I,string]) {return I}
  81.         return 0
  82.     }
  83.    
  84.     return 0
  85. }
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment