Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Amotz
  8. {
  9. public class Users
  10. {
  11. private int id;
  12. private string username;
  13. private string password;
  14. private bool isAdmin;
  15. private int approval;
  16. private Groups group;
  17. private DateTime regDate;
  18.  
  19. public int Id { get => id; set => id = value; }
  20. public string Username { get => username; set => username = value; }
  21. public string Password { get => password; set => password = value; }
  22. public bool IsAdmin { get => isAdmin; set => isAdmin = value; }
  23. public int Approval { get => approval; set => approval = value; }
  24. public Groups Group { get => group; set => group = value; }
  25. public DateTime RegDate { get => regDate; set => regDate = value; }
  26.  
  27. public static List<Users> AllUsers = new List<Users>();
  28.  
  29. public override string ToString()
  30. {
  31. return Username;
  32. }
  33.  
  34. public static void BackDoor() // Created the first username.
  35. {
  36. Users admin = new Users();
  37. admin.Username = "ornakash";
  38. admin.Password = "qerqer";
  39. admin.IsAdmin = true;
  40. admin.Approval = 1;
  41. admin.regDate = DateTime.Now;
  42. ApplicationForm.SetUser(admin);
  43. AllUsers.Add(admin);
  44. }
  45.  
  46. public static string GetUserById(int id)
  47. {
  48. foreach (Users users in AllUsers)
  49. {
  50. if(users.Id == id)
  51. {
  52. return users.Username;
  53. }
  54. }
  55. return "Not found";
  56. }
  57. public static int CheckLogin(string username, string password)
  58. {
  59. foreach (Users users in AllUsers)
  60. {
  61. if (users.Username == username && users.Password == password)
  62. {
  63. if (users.Approval == 0) return -1;
  64. if (users.Approval == -1) return -2;
  65. ApplicationForm.SetUser(users);
  66. return 1;
  67. }
  68. }
  69. return 0;
  70. }
  71. public static int RegisterUser(Users newUser)
  72. {
  73. foreach(Users users in AllUsers)
  74. {
  75. if(users.Username == newUser.Username) { return 0; } // Username is taken.
  76. }
  77. newUser.Id = Convert.ToInt32(AllUsers.Count()); // Last ID.
  78. newUser.Approval = 0;
  79. newUser.RegDate = DateTime.Now;
  80. AllUsers.Add(newUser);
  81. return Convert.ToInt32(AllUsers.Count());
  82. }
  83.  
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement