public UserRow(WinUser user) { Username = user.Name; Fullname = user.FullName; SID = user.SID; isActive = true; status = UserEdit.Base.STATUS.OK; }
private WinUser Serialize(UserRow userRow) { WinUser user = new WinUser(); user.Name = userRow.Username; user.SID = userRow.SID; user.FullName = userRow.Fullname; user.Identification = "Password OR Biometrics"; return(user); }
public bool AddUser(WinUser newUser) { foreach (WinUser user in _data.users) { if (user.SID == newUser.SID) { return(false); } } _data.users.Add(newUser); saveData(_path); return(true); }
public WinUser GetUser(string sid) { if (_data != null) { foreach (WinUser user in _data.users) { if (user.SID == sid) { WinUser retUser = (WinUser)user.Clone(); return(retUser); } } } return(null); }
public void RemoveUser(string sid) { WinUser userToRemove = null; foreach (WinUser user in _data.users) { if (user.SID == sid) { userToRemove = user; break; } } if (userToRemove != null) { _data.users.Remove(userToRemove); saveData(_path); } }
public bool UpdateUser(WinUser user, bool passwordChanged) { for (int i = 0; i < _data.users.Count; i++) { if (_data.users[i].SID == user.SID) { if (passwordChanged) { _data.users[i] = user; } else { String pass = _data.users[i].Password; _data.users[i] = user; _data.users[i].Password = pass; } saveData(_path); return(true); } } return(false); }
/// <summary> /// Update of UserGrid, read user list from windows, compare them to db, sort /// </summary> private void UpdateUsers() { Dictionary <String, String> userStatus = new Dictionary <String, String>(); List <UserRow> sortingQueue = new List <UserRow>(); ManagementObjectSearcher usersSearcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_UserAccount");// WHERE Disabled='false'"); ManagementObjectCollection users = usersSearcher.Get(); var localUsers = users.Cast <ManagementObject>().Where( u => (bool)u["LocalAccount"] == true && int.Parse(u["SIDType"].ToString()) == 1 && u["Name"].ToString() != "HomeGroupUser$" ); bool hasActiveAdmin = false; WinUser dbUser; String currUserName = WindowsIdentity.GetCurrent().Name; foreach (ManagementObject user in users) { UserRow newRow; bool isUserActive = false; bool isDisabled = (user["Disabled"].ToString() == "True"); dbUser = _db.GetUser(user["SID"].ToString()); if (dbUser != null) { // Check whether name changed if (dbUser.Name != user["Name"].ToString()) { dbUser.Name = user["Name"].ToString(); } // Check whether fullname changed if (dbUser.FullName != user["FullName"].ToString()) { dbUser.FullName = user["FullName"].ToString(); } _db.UpdateUser(dbUser, false); if (!dbUser.isDeactivated) { hasActiveAdmin = true; } isUserActive = true; newRow = new UserRow(user["Name"].ToString(), user["FullName"].ToString(), user["SID"].ToString(), isUserActive); if (dbUser.isDeactivated) { newRow.status = UserEdit.Base.STATUS.DEACTIVATED; } if (isDisabled) { userStatus.Add(user["SID"].ToString(), "Disabled"); newRow.status = UserEdit.Base.STATUS.DISABLED; } else { userStatus.Add(user["SID"].ToString(), "Active"); } sortingQueue.Add(newRow); } else if (!isDisabled) { userStatus.Add(user["SID"].ToString(), "Inactive"); newRow = new UserRow(user["Name"].ToString(), user["FullName"].ToString(), user["SID"].ToString(), isUserActive); sortingQueue.Add(newRow); } } if (!hasActiveAdmin) { var user = _db.GetUser(currUserSID); if (user != null) { _db.RestoreUser(currUserSID); foreach (UserRow record in sortingQueue.Where(item => item.SID == currUserSID)) { record.isActive = true; record.status = UserEdit.Base.STATUS.OK; userStatus[currUserSID] = "Active"; } } else { foreach (UserRow record in sortingQueue) { if (record.SID == currUserSID) { WinUser newUser = Serialize(record); if (_db.AddUser(newUser) == false) { MessageBox.Show("Can't add user"); } else { record.isActive = true; } break; } } } } //Check whether there are deleted users in DB List <WinUser> dbList = _db.GetAllUsers(); foreach (WinUser dbRecord in dbList) { if (!userStatus.ContainsKey(dbRecord.SID)) { UserRow tmpRow = new UserRow(dbRecord); tmpRow.status = UserEdit.Base.STATUS.DELETED; sortingQueue.Add(tmpRow); } } // sorting sortingQueue.Sort(); sortingQueue.Reverse(); userRows.Clear(); Action EmptyDelegate = delegate() { }; userGrid.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate); foreach (UserRow record in sortingQueue) { userRows.Add(record); } }
private void userGridClickReaction() { String fullname; List <Credential> tmpCredentials = new List <Credential>(); if (userGrid.SelectedIndex < 0) { return; } if (String.IsNullOrEmpty(userRows[userGrid.SelectedIndex].Fullname)) { fullname = userRows[userGrid.SelectedIndex].UsernameView; } else { fullname = userRows[userGrid.SelectedIndex].FullnameView; } tmpCredentials = _db.GetCredentials(userRows[userGrid.SelectedIndex].SID); if (tmpCredentials == null) { tmpCredentials = new List <Credential>(); } bool isLocalAdmin = false; if (userRows[userGrid.SelectedIndex].SID == currUserSID) { isLocalAdmin = true; } UserEdit.Base userEdit = new UserEdit.Base(fullname, tmpCredentials, pluginManager, appSet, _db.GetUser(userRows[userGrid.SelectedIndex].SID), userRows[userGrid.SelectedIndex].status, userRows[userGrid.SelectedIndex].Username, userRows[userGrid.SelectedIndex].SID, _db.GetAllUsers(), Licenser, isLocalAdmin); userEdit.Owner = this; try { userEdit.ShowDialog(); } catch (Exception ex) { Log.Error(ex.Message); } WinUser user = _db.GetUser(userRows[userGrid.SelectedIndex].SID); switch (userEdit.Result) { case UserEdit.Base.RESULT.UPDATE_USER: String res = "ok"; //userEdit.GetResultXml(); if (user == null) { user = Serialize(userRows[userGrid.SelectedIndex]); _db.AddUser(user); } if (userEdit.LoginType == XmlDB.LOGIN_TYPE.BIO) { int credCount = 0; foreach (var credo in tmpCredentials) { if (!(credo is PWDCredential)) { if ((credo as FingerCredential).fingers.Count() > 0) { credCount++; } } } if (credCount == 0) { userEdit.LoginType = XmlDB.LOGIN_TYPE.MIXED; MessageBox.Show("You haven't registered any biometric.\n Login type is set to 'Password or Biometrics'", "", MessageBoxButton.OK, MessageBoxImage.Warning); } } user.Password = userEdit.Password; user.Identification = XmlDB.LOGIN_STRING[(int)userEdit.LoginType]; _db.UpdateUser(user, true); if (res != null) { _db.SetCredentials(user.SID, tmpCredentials); } UpdateUsers(); userGrid.Items.Refresh(); break; case UserEdit.Base.RESULT.DELETE: if (user != null) { _db.RemoveUser(userRows[userGrid.SelectedIndex].SID); UpdateUsers(); userGrid.Items.Refresh(); } break; case UserEdit.Base.RESULT.DEACTIVATE: if (user != null) { _db.DeactivateUser(userRows[userGrid.SelectedIndex].SID); UpdateUsers(); userGrid.Items.Refresh(); } break; case UserEdit.Base.RESULT.RESTORE: if (user != null) { _db.RestoreUser(userRows[userGrid.SelectedIndex].SID); UpdateUsers(); userGrid.Items.Refresh(); } break; } if (userEdit.Result != UserEdit.Base.RESULT.CANCELED) { if (Licenser.State == IdentaZone.BioControls.Auxiliary.Licenser.STATE.ACTIVATED) { _db.Deploy(pluginManager.GetDeploymentList()); } } //userGrid.SelectedItem = null; }