internal void Logout(Action<LogoutOperation> completedAction, object userState) { CheckOKtoStartOperation(); m_Operation = UserContext.Authentication.Logout(completedAction, userState); App.Analytics.TrackEvent(Analytics.ActionValue.SignOut, LastUserName); }
public void LoginThenLogout() { AuthenticationService1 context = new AuthenticationService1(TestURIs.AuthenticationService1); FormsAuthentication service = new FormsAuthentication(); service.DomainContext = context; AuthenticationOperation ao = service.Login("manager", "manager"); this.EnqueueCompletion(() => ao); this.EnqueueCallback(() => { Assert.IsTrue(ao.User.Identity.IsAuthenticated, "Logged in user should be authenticated."); ao = service.Logout(false); }); this.EnqueueCompletion(() => ao); this.EnqueueCallback(() => { Assert.IsFalse(ao.User.Identity.IsAuthenticated, "Logged out user should not be authenticated."); ao = service.Logout(false); }); this.EnqueueTestComplete(); }
internal void Initialize() { LastUserName = Cookie.Read(g_LastLoginCookieName); CheckOKtoStartOperation(); m_Operation = UserContext.Authentication.LoadUser(OnLoadUserCompleted, null/*userState*/); }
internal void Login(string userName, string password, bool isPersistent, Action<LoginOperation> completedAction, object userState) { LoginParameters login = new LoginParameters(userName, password, isPersistent, null); CheckOKtoStartOperation(); m_Operation = UserContext.Authentication.Login(login, completedAction, userState); m_Operation.Completed += delegate(object sender, EventArgs e) { UpdateLastUserName(); }; }
/// <summary> /// Change password for a user. /// </summary> /// <param name="staffId">The staff identifier.</param> /// <param name="oldPasswordHash">The old password hash.</param> /// <param name="newPassword">The new password.</param> /// <param name="changePassword">The change password parameter.</param> /// <param name="newPasswordHash">The new password hash as output parameter.</param> /// <param name="newPasswordSalt">The new password salt as output parameter.</param> /// <param name="newPasswordHashAlgorithm">The new password hash algorithm as output parameter.</param> /// <param name="newPasswordLastChangedDateTime">The UTC date and time on which the password was changed.</param> /// <param name="newPasswordLastUpdatedOperation">The authentication operation for the last password update.</param> public void StaffChangePassword( string staffId, string oldPasswordHash, string newPassword, bool changePassword, out string newPasswordHash, out string newPasswordSalt, out string newPasswordHashAlgorithm, out DateTimeOffset newPasswordLastChangedDateTime, out AuthenticationOperation newPasswordLastUpdatedOperation) { const int StaffNotFoundErrorCode = 1; const int IncorrectPasswordErrorCode = 2; ReadOnlyCollection <object> results; try { results = this.InvokeMethod(StaffChangePasswordMethodName, new object[] { staffId, oldPasswordHash, newPassword, changePassword }); GetChangePasswordResult(results, out newPasswordHash, out newPasswordSalt, out newPasswordHashAlgorithm, out newPasswordLastChangedDateTime, out newPasswordLastUpdatedOperation); } catch (HeadquarterTransactionServiceException exception) { int?errorCode = (int?)exception.HeadquartersErrorData.FirstOrDefault(); switch (errorCode) { case StaffNotFoundErrorCode: case IncorrectPasswordErrorCode: throw new UserAuthenticationException( SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidPassword, exception, "User name or password mismatch."); case PasswordComplexityValidationFailed: throw new SecurityException( SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_PasswordComplexityRequirementsNotMet, exception, "The password complexity was not met."); case PasswordHistoryValidationFailed: throw new SecurityException( SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_PasswordHistoryRequirementsNotMet, exception, "The password history requirements were not met."); default: throw; } } }
private void OkBtn() { try { BusyIndie.BusyContent = "Identiteit controleren..."; BusyIndie.IsBusy = true; //hash hier string pswd = GetSHA256(passwordBox.Password); //string pswd = passwordBox.Password; this._op = this._service.Login(new LoginParameters(NaamBox.Text, pswd, false, null)); this._op.Completed += this.HandleCompletionEvent; } catch (Exception e) { MessageBox.Show("Ok Btn Catched: " + e.Message); } }
private void HandleCompletionEvent(object sender, EventArgs e) { try { if (_op.HasError) { MessageBox.Show(_op.Error.Message.ToString()); this.DialogResult = false; LogHelper.SendLog("Login Failed: " + _op.Error.Message.ToString(), LogType.error); } else if (_op.User != null && _op.User.Identity.IsAuthenticated) { eBrochureDomainContext ctx = new eBrochureDomainContext(); ctx.Load(ctx.GetGebruikersQuery()).Completed += (args, sender0) => { var gebr = (from g in ctx.Gebruikers where g.Naam.ToLower() == NaamBox.Text.ToLower() select new LoggedInUser() { GebruikersNaam = g.Naam, Rol = (UserRole)g.Rol_NR, ID = g.GebruikersID }).FirstOrDefault(); Acumulator.Instance().HuidigGebruiker = gebr; this.DialogResult = true; LogHelper.SendLog("Login by User: "******" - " + gebr.Rol.ToString(), LogType.activity); LogHelper.SendLog("Site accessed from: " + Application.Current.Resources["ClientIP"] + " by user: "******"Login Failed", LogType.error); this.DialogResult = false; } this._op = null; BusyIndie.IsBusy = false; } catch (Exception ex) { MessageBox.Show("Handle Complete Catched: " + ex.Message); } }
internal void SaveUser(Action<SaveUserOperation> completedAction, object userState) { CheckOKtoStartOperation(); m_Operation = UserContext.Authentication.SaveUser(completedAction, userState); }
/// <summary> /// Gets the new password hash and salt from the result object. /// </summary> /// <param name="changePasswordResult">The result for changing the password.</param> /// <param name="newPasswordHash">The new password hash as output parameter.</param> /// <param name="newPasswordSalt">The new password salt as output parameter.</param> /// <param name="newPasswordHashAlgorithm">The new password hash algorithm as output parameter.</param> /// <param name="newPasswordLastChangedDateTime">The UTC date and time on which the password was changed.</param> /// <param name="newPasswordLastUpdatedOperation">The authentication operation for the last password update.</param> private static void GetChangePasswordResult(ReadOnlyCollection <object> changePasswordResult, out string newPasswordHash, out string newPasswordSalt, out string newPasswordHashAlgorithm, out DateTimeOffset newPasswordLastChangedDateTime, out AuthenticationOperation newPasswordLastUpdatedOperation) { if (changePasswordResult == null || changePasswordResult.Count < ChangePasswordObjectSize) { throw new Microsoft.Dynamics.Commerce.Runtime.CommunicationException(CommunicationErrors.Microsoft_Dynamics_Commerce_Runtime_HeadquarterResponseParsingError); } newPasswordHash = (string)changePasswordResult[0]; newPasswordSalt = (string)changePasswordResult[1]; newPasswordHashAlgorithm = (string)changePasswordResult[2]; newPasswordLastChangedDateTime = new DateTimeOffset((DateTime)changePasswordResult[3]); newPasswordLastUpdatedOperation = (AuthenticationOperation)changePasswordResult[4]; }
/// <summary> /// Logs an authentication request. /// </summary> /// <param name="context">The request context.</param> /// <param name="staffId">The staff identifier.</param> /// <param name="logOnStatus">The log status.</param> /// <param name="authenticationOperation">The authentication operation.</param> internal static void LogAuthenticationRequest(RequestContext context, string staffId, AuthenticationStatus logOnStatus, AuthenticationOperation authenticationOperation) { LogAuthenticationDataRequest dataRequest = new LogAuthenticationDataRequest(context.GetPrincipal().ChannelId, staffId, logOnStatus, authenticationOperation); context.Runtime.Execute <NullResponse>(dataRequest, context); }