C3032
2025-12-20 15492363f898704b51afce5f1c88fa3b754cbabc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace SmartScanner
{
    public class User
    {
        public string Username { get; set; }
        public string Password { get; set; }
        public UserRole Role { get; set; }
    }
 
    public enum UserRole
    {
        Administrator,
        Technician
    }
 
    public static class UserManager
    {
        public static List<User> UserList { get; } = new List<User>
    {
        new User { Username = "admin", Password = "123", Role = UserRole.Administrator },
        //new User { Username = "admin2", Password = "admin456", Role = UserRole.Administrator },
        //new User { Username = "tech1", Password = "tech123", Role = UserRole.Technician },
        //new User { Username = "tech2", Password = "tech456", Role = UserRole.Technician }
    };
 
        public static User CurrentUser { get; private set; }
 
        public static bool Authenticate(string username, string password)
        {
            var user = UserList.FirstOrDefault(u => u.Username == username && u.Password == password);
            if (user != null)
            {
                CurrentUser = user;
                return true;
            }
            return false;
        }
 
        public static bool HasAdministratorPrivilege()
        {
            return CurrentUser?.Role == UserRole.Administrator;
        }
    }
}