public void Exists_ReturnsTrue_WhenUserExist() { // arrange var name = _generator.RandomName; _installer.Install(name, _generator.RandomName); // act var result = new LocalUserInfo(name).Exists(); // assert result.Should().BeTrue(); }
public async Task StoreToken(LocalUserInfo localUserInfo) { try { await storageService.SetItemAsync(Constants.UserKey, localUserInfo); } catch (Exception ex) { DebugPrint.Log("StoreToken"); DebugPrint.Log(ex.Message); await storageService.ClearAsync(); } }
internal LocalUserInfo MapToLocalUserInfo(PSObject result) { if (result == null) { return(null); } var properties = new PsObjectProperties(result); var flags = properties.Get("UserFlags") ?? default(int); var userFlags = new UserFlags((int)flags); var user = new LocalUserInfo(); user.Sid = result.Properties["SecurityId"]?.Value as string; user.Name = properties.Get <string>("Name"); user.FullName = properties.Get <string>("FullName"); user.Description = properties.Get <string>("Description"); user.PasswordCanBeChangedByUser = userFlags.PasswordCanBeChangedByUser; user.PasswordRequired = userFlags.PasswordRequired; user.AccountDisabled = userFlags.AccountDisabled; user.AccountLocked = userFlags.AccountLocked; user.PasswordMaxBadAttempts = properties.GetValue <int>("MaxBadPasswordsAllowed"); user.PasswordBadAttemptsInterval = properties.GetTimeSpan("LockoutObservationInterval"); user.AutoUnlockInterval = properties.GetTimeSpan("AutoUnlockInterval"); user.LastLogon = properties.GetDateTime("LastLogin"); user.PasswordMinLength = properties.GetValue <int>("MinPasswordLength"); var accountExpirationDate = properties.GetTimeSpan("AccountExpirationDate"); var passwordAge = properties.GetTimeSpan("PasswordAge"); var maxPasswordAge = properties.GetTimeSpan("MaxPasswordAge"); var passwordExpired = properties.GetValue <int>("PasswordExpired"); user.PasswordLastChange = DateTime.Now.Add(passwordAge.Negate()).Date; user.AccountExpires = GetExpirationDate(TimeSpan.Zero, accountExpirationDate); user.PasswordExpires = userFlags.PasswordCanExpire ? GetExpirationDate(passwordAge, maxPasswordAge) : null; user.PasswordMustBeChangedAtNextLogon = IsPasswordChangeRequiredOnNextLogon(passwordAge, passwordExpired); return(user); }
public void Get_WhenUSer_IsVisible_AndSpecialAccountRegistryExist() { // arrange var userName = _generator.RandomName; _installer.Install(userName, _generator.RandomName); UserHelper.AddSpecialAccountRegistry(); // act var user = new LocalUserInfo(userName); // assert user.IsVisible.Should().BeTrue(); }
public void Get_WhenAccountDisabled_ReturnsProperFlag() { // arrange var userName = _generator.RandomName; _installer.Install(userName, _generator.RandomName); UserHelper.SetUserFlag(userName, 0x2, true); // act var user = new LocalUserInfo(userName); // assert user.AccountDisabled.Should().BeTrue(); }
public void Get_WhenPasswordNeverExpires_ReturnsNullDateTime() { // arrange var userName = _generator.RandomName; _installer.Install(userName, _generator.RandomName); UserHelper.SetUserFlag(userName, 0x10000, true); // act var user = new LocalUserInfo(userName); // assert user.PasswordExpires.Should().BeNull(); }
public void Get_WhenPasswordNotRequired_ReturnsProperFlag() { // arrange var userName = _generator.RandomName; _installer.Install(userName, _generator.RandomName); UserHelper.SetUserFlag(userName, 0x20, true); // act var user = new LocalUserInfo(userName); // assert user.PasswordRequired.Should().BeFalse(); }
public void Get_WhenPasswordExpired_ReturnsProperFlag() { // arrange var userName = _generator.RandomName; _installer.Install(userName, _generator.RandomName); UserHelper.SetPasswordExipred(userName, true); UserHelper.GetPasswordExpired(userName).Should().BeTrue(); // act var user = new LocalUserInfo(userName); // assert user.PasswordMustBeChangedAtNextLogon.Should().BeTrue(); }
public void Get_WhenUser_IsHidden_ReturnProperFlag() { // arrange var userName = _generator.RandomName; _installer.Install(userName, _generator.RandomName); UserHelper.AddSpecialAccountRegistry(); UserHelper.HideUser(userName); UserHelper.GetUserVisibility(userName).Should().BeFalse(); // act var user = new LocalUserInfo(userName); // assert user.IsVisible.Should().BeFalse(); }
public void Exists_ReturnsFalse_WhenUserNotExist() { // arrange var name = _generator.RandomName; _installer.Install(name, _generator.RandomName); var user = new LocalUserInfo(name); _installer.Remove(name); // act var result = user.Exists(); // assert result.Should().BeFalse(); }
public void LogoutResponse(JSONNode response) { LoadingWindowUI.Instance.Leave(this); LocalUserInfo.DisposeCurrentUser(); if (response["error"] != null) { Debug.Log("Session could not be done: " + response["error"].Value); } else { Debug.Log(response); } ResetLoginFields(); MoveToMenu(0); }
public void GetLocalFilePath() { ///Xml转json XElement xele = XElement.Load(Path.Combine(localUserInfoFilepath, FileName)); var item = (from ele in xele.DescendantsAndSelf("User") select ele).ToList(); if (item.Count > 0) //存在用户 { XmlDocument document = new XmlDocument(); document.LoadXml(xele.ToString()); string str = JsonConvert.SerializeXmlNode(document); JObject json = (JObject)JsonConvert.DeserializeObject(str); //判断是否存在“[”“]” 来判断是否为多用户 正则匹配 Regex reg = new Regex(@"\[[^\[\]]+\]"); MatchCollection Users = reg.Matches(str); bool UsersCount = Users.Count > 0; //大于0 至少有两个用户 等于0 只存在一个用户 int index = 0; if (UsersCount) { for (int i = 0; i < json["Root"]["User"].Count(); i++) { var cc = json["Root"]["User"][i]; LocalUserInfo.Add(new LocalUserInfo() { Index = index + 1, Phone = cc["Phone"].ToString(), Pwd = cc["Pwd"].ToString(), }); index++; } } else { var cc = json["Root"]["User"]; LocalUserInfo.Add(new LocalUserInfo() { Index = index + 1, Phone = cc["Phone"].ToString(), Pwd = cc["Pwd"].ToString(), }); } } }
public void Remove_Should_Delete_NewUser_AndProfile() { // arrange var userName = _generator.RandomName; _installer.InstallWithProfile(userName, _generator.RandomName); // act var user = new LocalUserInfo(userName); user.RemoveWithProfile(); // assert var fetchedUser = UserHelper.GetUser(userName); var isProfileExists = UserHelper.IsProfileExists(userName); fetchedUser.Should().BeNull(); isProfileExists.Should().BeFalse(); }
public void SetUserFullName_ThrowsExcpction_WhenUserNotExist() { // arrange var userName = _generator.RandomName; var fullName = "new fullName"; _installer.Install(userName, _generator.RandomName); var user = new LocalUserInfo(userName); _installer.Remove(userName); // act Action act = () => user.Change() .FullName(fullName) .Apply(); // assert act.Should().Throw <MethodInvocationException>(); }
/// <summary> /// 获取管理员信息 /// </summary> /// <param name="UID">用户编号</param> /// <returns>管理员信息</returns> public MasterUserInfo GetMaster() { LocalUserInfo LocalUser = GetLoginTicket(TicketType.MasterCookieName); if (LocalUser == null) { return(null); } MasterUserInfo MasterUser = new MaterLogin().GetMasterInfo(LocalUser.UID); if (ValidateUser(MasterUser)) { return(MasterUser); } else { return(null); } }
public void SetUserDescription_ThrowsExcpeiton_WhenUserNotExist() { // arrange var userName = _generator.RandomName; var description = "new description"; _installer.Install(userName, _generator.RandomName); var user = new LocalUserInfo(userName); _installer.Remove(userName); // act Action act = () => user.Change() .Description(description) .Apply(); // assert act.Should().Throw <MethodInvocationException>(); }
private void DelSaveUser(object[] x) { Button Btn = x[0] as Button; int _index = JObjectHelper.GetStrNum(Btn.Tag.ToString()) - 1; string UserPhone = LocalUserInfo[_index].Phone; LocalUserInfo.RemoveAt(_index); //删除本地用户 XElement xele = XElement.Load(Path.Combine(localUserInfoFilepath, FileName)); //MessageBox.Show(xele.Element("Phone").Value) var item = (from ele in xele.Elements("User") where (string)ele.Element("Phone") == UserPhone select ele).FirstOrDefault(); if (item != null) { item.Remove(); } xele.Save(Path.Combine(localUserInfoFilepath, FileName)); sort(); }
public void CopyProperties(LocalUserInfo info, LocalUserInfo source) { info.IsVisible = source.IsVisible; info.AccountDisabled = source.AccountDisabled; info.AccountExpires = source.AccountExpires; info.AccountLocked = source.AccountLocked; info.AutoUnlockInterval = source.AutoUnlockInterval; info.Description = source.Description; info.FullName = source.FullName; info.LastLogon = source.LastLogon; info.Name = source.Name; info.PasswordBadAttemptsInterval = source.PasswordBadAttemptsInterval; info.PasswordCanBeChangedByUser = source.PasswordCanBeChangedByUser; info.PasswordExpires = source.PasswordExpires; info.PasswordBadAttemptsInterval = source.PasswordBadAttemptsInterval; info.PasswordMaxBadAttempts = source.PasswordMaxBadAttempts; info.PasswordMinLength = source.PasswordMinLength; info.PasswordMustBeChangedAtNextLogon = source.PasswordMustBeChangedAtNextLogon; info.PasswordRequired = source.PasswordRequired; info.PasswordLastChange = source.PasswordLastChange; }
public async Task SubmitLogin() { isBusy = true; loginResult.Message = "load"; loginResult = await loginService.Login(LoginModel); if (loginResult.IsSuccess) { var userInfo = new LocalUserInfo() { AccessToken = loginResult.Message, Email = loginResult.UserInfo["Email"].Trim(), FirstName = loginResult.UserInfo["FirstName"].Trim(), LastName = loginResult.UserInfo["LastName"].Trim(), Id = loginResult.UserInfo[System.Security.Claims.ClaimTypes.NameIdentifier], }; await storageService.SetItemAsync("User", userInfo); await authenticationStateProvider.GetAuthenticationStateAsync(); isBusy = false; } }
public void MapToUserModel_Maps_WhenOk() { // arrange var info = new LocalUserInfo { Name = "test name", Description = "test description", FullName = "full name", AccountExpires = new DateTime(2000, 1, 1), PasswordMaxBadAttempts = 1, PasswordMinLength = 2, PasswordRequired = true, PasswordExpires = new DateTime(2000, 1, 2), PasswordBadAttemptsInterval = TimeSpan.Zero, PasswordCanBeChangedByUser = true, PasswordLastChange = new DateTime(2000, 1, 3), PasswordMustBeChangedAtNextLogon = true }; // act var model = _mapper.MapToUserModel(info); // assert model.Name.Should().Be(info.Name); model.AccountExpires.Should().Be(info.AccountExpires); model.Description.Should().Be(info.Description); model.FullName.Should().Be(info.FullName); model.Password.Should().Be(null); model.PasswordBadAttemptsInterval.Should().Be(info.PasswordBadAttemptsInterval); model.PasswordCanBeChangedByUser.Should().Be(info.PasswordCanBeChangedByUser); model.PasswordExpires.Should().Be(info.PasswordExpires); model.PasswordLastChange.Should().Be(info.PasswordLastChange); model.PasswordMaxBadAttempts.Should().Be(info.PasswordMaxBadAttempts); model.PasswordMinLength.Should().Be(info.PasswordMinLength); model.PasswordMustBeChangedAtNextLogon.Should().Be(info.PasswordMustBeChangedAtNextLogon); model.PasswordRequired.Should().Be(info.PasswordRequired); }
public void Get_Fetches_User() { // arrange var originalUser = new LocalUserCreateModel { Name = _generator.RandomName, AccountExpires = null, Password = null, Description = "test description", FullName = "test user to delete" }; _installer.Install(originalUser); // act var actualUser = new LocalUserInfo(originalUser.Name); // assert actualUser.Name.Should().Be(originalUser.Name); actualUser.Description.Should().Be(originalUser.Description); actualUser.AccountExpires.Should().Be(originalUser.AccountExpires); actualUser.FullName.Should().Be(originalUser.FullName); actualUser.PasswordLastChange.GetValueOrDefault().Date.Should().Be(UserHelper.GetPasswordLastSet(originalUser.Name).GetValueOrDefault()); actualUser.PasswordMaxBadAttempts.Should().Be(UserHelper.GetPasswordMaxBadAttempts(originalUser.Name)); actualUser.PasswordBadAttemptsInterval.Should().Be(UserHelper.GetPasswordBadAttemptsInterval(originalUser.Name)); actualUser.PasswordMustBeChangedAtNextLogon.Should().Be(false); actualUser.PasswordExpires.GetValueOrDefault().Date.Should().Be(UserHelper.GetPasswordExpirationDate(originalUser.Name).GetValueOrDefault().Date); actualUser.PasswordMinLength.Should().Be(UserHelper.GetPasswordMinLength(originalUser.Name)); actualUser.PasswordCanBeChangedByUser.Should().Be(true); actualUser.PasswordRequired.Should().Be(true); actualUser.AutoUnlockInterval.Should().Be(UserHelper.GetAutoUnlockInterval(originalUser.Name)); actualUser.LastLogon.Should().Be(UserHelper.GetLastLogon(originalUser.Name)); actualUser.IsVisible.Should().BeTrue(); }
public override async Task <AuthenticationState> GetAuthenticationStateAsync() { if (await _storageService.ContainKeyAsync("User")) { LocalUserInfo userInfo = await _storageService.GetItemAsync <LocalUserInfo>("User"); Claim[] claims = new[] { new Claim("Email", userInfo.Email), new Claim("FirstName", userInfo.FirstName), new Claim("LastName", userInfo.LastName), new Claim("AccessToken", userInfo.AccessToken), new Claim(ClaimTypes.NameIdentifier, userInfo.Id), }; ClaimsIdentity identity = new ClaimsIdentity(claims, "BearerToken"); ClaimsPrincipal user = new ClaimsPrincipal(identity); AuthenticationState state = new AuthenticationState(user); NotifyAuthenticationStateChanged(Task.FromResult(state)); return(state); } return(new AuthenticationState(new ClaimsPrincipal())); }
internal UserModel MapToUserModel(LocalUserInfo info) { if (info == null) { return(null); } return(new UserModel { Name = info.Name, Description = info.Description, Password = null, FullName = info.FullName, PasswordMaxBadAttempts = info.PasswordMaxBadAttempts, PasswordRequired = info.PasswordRequired, PasswordExpires = info.PasswordExpires, PasswordMinLength = info.PasswordMinLength, AccountExpires = info.AccountExpires, PasswordBadAttemptsInterval = info.PasswordBadAttemptsInterval, PasswordCanBeChangedByUser = info.PasswordCanBeChangedByUser, PasswordLastChange = info.PasswordLastChange, PasswordMustBeChangedAtNextLogon = info.PasswordMustBeChangedAtNextLogon }); }
/// <summary> /// 身份验证。 /// </summary> /// <param name="authen"></param> /// <param name="account"></param> /// <param name="password"></param> /// <returns></returns> public void Authentication(EnumUserAuthen authen, string account, string password, UserAuthenticationHandler handler) { try { if (string.IsNullOrEmpty(account)) throw new ArgumentNullException("account", "账号为空!"); if (string.IsNullOrEmpty(password)) throw new ArgumentNullException("password", "密码为空!"); this.RaiseChanged("开始连接服务器,请稍后..."); this.poxy.BeginVerifyUserIdentity((int)authen, account, password, new AsyncCallback(delegate(IAsyncResult callback) { this.RaiseChanged("等待服务器返回,请稍后..."); try { Impl.CallResult callResult = this.poxy.EndVerifyUserIdentity(callback); this.RaiseChanged("已返回数据,开始分析..."); if (callResult.ResultCode == 0) { if (handler != null) { string[] arr = callResult.ResultMessage.Split(','); if (arr != null && arr.Length >= 3) { LocalUserInfo info = new LocalUserInfo(); info.SchoolID = this.cert.SchoolID; info.UserAccount = account; info.Password = password; info.UserID = arr[0]; info.UserCode = arr[1]; info.UserName = arr[2]; handler(info, null); } } this.RaiseChanged("身份验证通过..."); } else { string err = "身份验证失败," + callResult.ResultMessage; handler(null, new Exception(err)); } } catch (Exception) { this.RaiseChanged("发生异常"); handler(null, new Exception("发生网络异常")); } }), null); } catch (Exception e) { this.RaiseChanged("发生异常:" + e.Message); handler(null, new Exception("发生网络异常")); } }
private static void ToLocalUserInfo() { if (string.IsNullOrEmpty(mContent)) return; UserInfos.Clear(); string[] userpass = mContent.Split(new char[1] { ';' }); if (userpass == null) return; for (int i = 0; i < userpass.Length; ++i) { string[] up = userpass[i].Split(new char[1] { ',' }); if (up == null || up.Length != 2) continue; LocalUserInfo info = new LocalUserInfo(); info.username = up[0]; info.password = up[1]; UserInfos.Enqueue(info); } }
public static LocalUserInfo[] LoadUserInfo() { LoadProfiler(); ToLocalUserInfo(); LocalUserInfo[] infos = new LocalUserInfo[UserInfos.Count]; int i = 0; foreach (LocalUserInfo e in UserInfos) { infos[i] = new LocalUserInfo(); infos[i].username = e.username; infos[i].password = e.password; i++; } return infos; }
public static void SaveUserInfo(string username, string password) { bool saved = false; foreach(LocalUserInfo e in UserInfos) { if (e.username == username) { e.password = password; saved = true; } } if (saved) return; LocalUserInfo removed = null; removed = new LocalUserInfo(); removed.username = username; removed.password = password; UserInfos.Enqueue(removed); ToString(); SaveProfiler(); }
/// <summary> /// 更新管理员信息 /// </summary> /// <param name="User">用户编号</param> public void UpdateMasterInfo(MasterUserInfo User) { LocalUserInfo LocalUser = GetLoginTicket(TicketType.MasterCookieName); new MaterLogin().UpdateMasterInfo(User); }