Exemple #1
0
        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);
        }
Exemple #2
0
        public static bool ChangePassword(UserLogin user, string password)
        {
            try
            {
                user.Password = PasswordEncrypter.EncryptPassword(user.Username.ToLower(), password);
                database.SaveChanges();
            }
            catch (Exception e)
            {
                ESB2ExceptionEventLog.LogExceptionEvent(e);
                return(false);
            }

            return(true);
        }
        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();
        }
Exemple #4
0
 private static bool ValidatePassword(UserLogin user, string password)
 {
     return(user.Password.SequenceEqual(PasswordEncrypter.EncryptPassword(user.Username, password)));
 }
Exemple #5
0
 private void CreateAdminAccountClicked(object sender, RoutedEventArgs e)
 {
     password = PasswordEncrypter.EncryptPassword("admin", password1.Password);
     Close();
 }