예제 #1
0
        private static void CreateAdminAccount()
        {
            var createAdminAccount = new CreateAdminAccount();

            createAdminAccount.ShowDialog();

            if (createAdminAccount.Password != null)
            {
                database.Users.Add(new UserLogin()
                {
                    Username               = "******",
                    Firstname              = "Administrator",
                    Lastname               = "Account",
                    UserPermissions        = UserPermissions.Admin,
                    Password               = createAdminAccount.Password,
                    LastLogin              = DateTime.Today,
                    FailedLoginCount       = 0,
                    FailedLoginTimestamp   = DateTime.Today.AddDays(-1),
                    AccountLocked          = false,
                    UserMustChangePassword = false,
                });

                database.SaveChanges();
                ESB2UserEventLog.LogUserEvent("admin", EventLoggerEvents.UserCreated);
            }
        }
예제 #2
0
파일: UserList.cs 프로젝트: dsbjax/ESB2
        public static UserLogin AddUser(string username, string firstname, string lastname)
        {
            UserLogin newUser = null;

            if (!database.Users.Any(u => u.Username == username))
            {
                newUser = new UserLogin()
                {
                    Username               = username.ToLower(),
                    Firstname              = firstname,
                    Lastname               = lastname,
                    UserPermissions        = UserPermissions.ReportsOnly,
                    Password               = PasswordEncrypter.EncryptPassword(username.ToLower(), "ffj" + username.ToLower()),
                    LastLogin              = DateTime.Today,
                    FailedLoginCount       = 0,
                    FailedLoginTimestamp   = DateTime.Today.AddDays(-1),
                    AccountLocked          = false,
                    UserMustChangePassword = true,
                };

                database.Users.Add(newUser);
                database.SaveChanges();
                ESB2UserEventLog.LogUserEvent(newUser.Username, EventLoggerEvents.UserCreated);

                LoadUserList();
            }

            return(newUser);
        }
예제 #3
0
파일: ESB2Login.cs 프로젝트: dsbjax/ESB2
        public static User Login()
        {
            var  loginDialog = new UserLoginDialog();
            User user        = null;

            try
            {
                loginDialog.ShowDialog();
                if ((bool)loginDialog.DialogResult)
                {
                    user = users.FirstOrDefault(u => u.Username.Equals(loginDialog.Username.ToLower()));

                    if (user != null)
                    {
                        user = ProcessLogin((UserLogin)user, loginDialog.Password);
                    }
                    else
                    {
                        new InvalidUsernameDialog().ShowDialog();
                        ESB2UserEventLog.LogUserEvent(loginDialog.Username, EventLoggerEvents.InvalidUsername);
                    }
                }
            }catch (Exception e)
            {
                ESB2ExceptionEventLog.LogExceptionEvent(e);
            }

            return(user);
        }
예제 #4
0
파일: SystemsList.cs 프로젝트: dsbjax/ESB2
        public static SystemGroup AddNewSystemGroup(string nomenclature, string description)
        {
            var newSystemsGroup = new SystemGroup()
            {
                Nomenclature = nomenclature,
                Description  = description
            };

            database.SystemGroupings.Add(newSystemsGroup);

            database.SaveChanges();
            ESB2UserEventLog.LogUserEvent(CurrentUserNotifications.CurrentUser.Username, EventLoggerEvents.SystemGroupAdded);
            LoadSystemsList();

            return(newSystemsGroup);
        }
예제 #5
0
파일: ESB2Login.cs 프로젝트: dsbjax/ESB2
        private static UserLogin HandleAccountLocked(UserLogin user)
        {
            var locked = DateTime.Now - user.FailedLoginTimestamp;

            if (locked.Minutes < 15)
            {
                new LockedAccountDialog().ShowDialog();
                user = null;
            }
            else
            {
                user.AccountLocked = false;
                ESB2UserEventLog.LogUserEvent(user.Username, EventLoggerEvents.UserAccountUnlocked);
            }

            return(user);
        }
예제 #6
0
파일: SystemsList.cs 프로젝트: dsbjax/ESB2
        public static Equipment AddNewEquipment(EquipmentGroup selectedEquipmentGroup, string title, string description)
        {
            var newEquipment = new Equipment()
            {
                Nomenclature = title,
                Description  = description
            };

            selectedEquipmentGroup.Equipment.Add(newEquipment);

            database.SaveChanges();
            ESB2UserEventLog.LogUserEvent(CurrentUserNotifications.CurrentUser.Username, EventLoggerEvents.EquipmentAdded);

            LoadSystemsList();

            return(newEquipment);
        }
예제 #7
0
        private void ChangePasswordClick(object sender, RoutedEventArgs e)
        {
            var currentEncrypted     = PasswordEncrypter.EncryptPassword(user.Username, currrent.Password);
            var newPasswordEncrypted = PasswordEncrypter.EncryptPassword(user.Username, password1.Password);

            if (currentEncrypted.SequenceEqual(user.Password))
            {
                user.Password = newPasswordEncrypted;
                user.UserMustChangePassword = false;
                ESB2UserEventLog.LogUserEvent(user.Username, EventLoggerEvents.UserPasswordChanged);
            }
            else
            {
                new PasswordChangeFailDialog().ShowDialog();
                new ChangePasswordDialog(user).ShowDialog();
            }

            Close();
        }
예제 #8
0
파일: ESB2Login.cs 프로젝트: dsbjax/ESB2
        private static User ProcessLogin(UserLogin user, string password)
        {
            if (user.AccountLocked)
            {
                user = HandleAccountLocked(user);
            }

            if (user == null)
            {
                return(user);
            }

            if (ValidatePassword(user, password))
            {
                user.FailedLoginCount = 0;
                user.LastLogin        = DateTime.Now;
                ESB2UserEventLog.LogUserEvent(user.Username, EventLoggerEvents.LoginSuccess);

                if (user.UserMustChangePassword)
                {
                    new ChangePasswordDialog(user).ShowDialog();
                }
            }
            else
            {
                user.FailedLoginCount++;

                user.FailedLoginTimestamp = DateTime.Now;
                new LoginFailDialog().ShowDialog(user.FailedLoginCount);
                ESB2UserEventLog.LogUserEvent(user.Username, EventLoggerEvents.LoginFail);

                user.AccountLocked = user.FailedLoginCount == 5;
                if (user.AccountLocked)
                {
                    ESB2UserEventLog.LogUserEvent(user.Username, EventLoggerEvents.UserAccountLocked);
                }

                user = null;
            }

            database.SaveChanges();
            return(user);
        }
예제 #9
0
파일: ESB2Login.cs 프로젝트: dsbjax/ESB2
 public static User Logout(User currentUser)
 {
     ESB2UserEventLog.LogUserEvent(currentUser.Username, EventLoggerEvents.Logout);
     return(null);
 }