Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Amotz
- {
- public class Users
- {
- private int id;
- private string username;
- private string password;
- private bool isAdmin;
- private int approval;
- private Groups group;
- private DateTime regDate;
- public int Id { get => id; set => id = value; }
- public string Username { get => username; set => username = value; }
- public string Password { get => password; set => password = value; }
- public bool IsAdmin { get => isAdmin; set => isAdmin = value; }
- public int Approval { get => approval; set => approval = value; }
- public Groups Group { get => group; set => group = value; }
- public DateTime RegDate { get => regDate; set => regDate = value; }
- public static List<Users> AllUsers = new List<Users>();
- public override string ToString()
- {
- return Username;
- }
- public static void BackDoor() // Created the first username.
- {
- Users admin = new Users();
- admin.Username = "ornakash";
- admin.Password = "qerqer";
- admin.IsAdmin = true;
- admin.Approval = 1;
- admin.regDate = DateTime.Now;
- ApplicationForm.SetUser(admin);
- AllUsers.Add(admin);
- }
- public static string GetUserById(int id)
- {
- foreach (Users users in AllUsers)
- {
- if(users.Id == id)
- {
- return users.Username;
- }
- }
- return "Not found";
- }
- public static int CheckLogin(string username, string password)
- {
- foreach (Users users in AllUsers)
- {
- if (users.Username == username && users.Password == password)
- {
- if (users.Approval == 0) return -1;
- if (users.Approval == -1) return -2;
- ApplicationForm.SetUser(users);
- return 1;
- }
- }
- return 0;
- }
- public static int RegisterUser(Users newUser)
- {
- foreach(Users users in AllUsers)
- {
- if(users.Username == newUser.Username) { return 0; } // Username is taken.
- }
- newUser.Id = Convert.ToInt32(AllUsers.Count()); // Last ID.
- newUser.Approval = 0;
- newUser.RegDate = DateTime.Now;
- AllUsers.Add(newUser);
- return Convert.ToInt32(AllUsers.Count());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement