/// <summary> /// Raises the <c>AuthenticateUser</c> event. /// </summary> protected virtual void OnAuthenticateUser(AuthenticateUserEventArgs e) { // raise... if (AuthenticateUser != null) { AuthenticateUser(this, e); } }
public static void dlgLogin_AuthenticateUser(object sender, AuthenticateUserEventArgs e) { #if LEADTOOLS_V19_OR_LATER if (e.LoginType == LoginType.SmartcardPin) { AuthenticateCardUser(sender, e); return; } #endif // // Once user is logged in we need to check to see if the user password // has expired. // _UserName = e.Username; try { if (UserManager.Authenticate(e.Username, e.Password)) { if (UserManager.IsPasswordExpired(e.Username)) { StorageServer.UI.PasswordDialog dlgPassword = new StorageServer.UI.PasswordDialog(); dlgPassword.Text = "Reset Expired Password"; dlgPassword.ValidatePassword += new EventHandler <ValidatePasswordEventArgs>(dlgPassword_ValidatePassword); if (dlgPassword.ShowDialog(sender as Form) == DialogResult.OK) { UserManager.ResetPassword(e.Username, dlgPassword.Password); } else { e.Cancel = true; } } } else { Messager.ShowError(sender as Form, "Invalid user name or password."); e.InvalidCredentials = true; } } catch (Exception exception) { Messager.ShowError(sender as Form, exception); e.InvalidCredentials = true; } if (!e.Cancel && !e.InvalidCredentials) { IOptionsDataAccessAgent optionsAgent = DataAccessServices.GetDataAccessService <IOptionsDataAccessAgent>(); optionsAgent.Set <string>("LastUser", e.Username); } }
private void buttonOK_Click(object sender, System.EventArgs e) { string username = this.textUsername.Text; string password = this.textPassword.Text; // check... if (this.CurrentConnectionSettings == null) { Alert.ShowWarning(this, "You must select a connection."); return; } // set... Database.SetDefaultDatabase(this.CurrentConnectionSettings); // check... if (this.UsernameRequired && (username == null || username.Length == 0)) { Alert.ShowWarning(this, "You must enter your username."); return; } if (this.PasswordRequired && (password == null || password.Length == 0)) { Alert.ShowWarning(this, "You must enter your password."); return; } // validate... AuthenticateUserEventArgs validateArgs = new AuthenticateUserEventArgs(username, password); try { this.AuthenticateUser(this, validateArgs); } catch (Exception ex) { Alert.ShowWarning(this, "Failed to logon user.", ex); return; } // what now? if (validateArgs.IsAuthenticated) { // remember... Runtime.Current.UserSettings["LastUsername"] = username; Runtime.Current.UserSettings["LastConnection"] = this.CurrentConnectionSettings.Name; // ok... this.DialogResult = DialogResult.OK; } }
private static void dlgLogin_AuthenticateUser(object sender, AuthenticateUserEventArgs e) { // // Once user is logged in we need to check to see if the user password // has expired. // string errorString = string.Empty; _UserName = e.Username; UserManager.AuthenticateResult result = UserManager.Authenticate(e.Username, e.Password, out errorString); if (result == UserManager.AuthenticateResult.Success) { if (UserManager.IsPasswordExpired(e.Username)) { PasswordDialog dlgPassword = new PasswordDialog(); dlgPassword.Text = "Reset Expired Password"; dlgPassword.ValidatePassword += new EventHandler <ValidatePasswordEventArgs>(dlgPassword_ValidatePassword); if (dlgPassword.ShowDialog(sender as Form) == DialogResult.OK) { UserManager.ResetPassword(e.Username, dlgPassword.Password); } else { e.Cancel = true; } } } else if (result == UserManager.AuthenticateResult.InvalidUser) { Messager.ShowError(sender as Form, "Invalid user name or password."); e.InvalidCredentials = true; } else if (result == UserManager.AuthenticateResult.ErrorInvalidDatabase) { Messager.ShowError(sender as Form, "Invalid Database.\n\nThe configured database does not contain a 'Users' table. Please run " + Program.PacsDatabaseConfigurationDemoNames[0] + " to connect to the correct database."); e.InvalidCredentials = false; e.Cancel = true; } else { Messager.ShowError(sender as Form, errorString); e.InvalidCredentials = false; e.Cancel = true; } }
private static bool AuthenticateCardUser(object sender, AuthenticateUserEventArgs e) { if (e.LoginType != LoginType.SmartcardPin) { return(false); } string error = string.Empty; string warning = string.Empty; string information = string.Empty; int pinCounter; string ediNumber; AuthenticateCardUserResult isValid = UserManager.AuthenticateCardUser(e.CardReaderIndex, e.Pin, e.CardReaderValidatePinOnly, out ediNumber, out pinCounter); switch (isValid) { case AuthenticateCardUserResult.Success: e.InvalidCredentials = false; e.EdiNumber = ediNumber; break; case AuthenticateCardUserResult.UnknownError: error = "Card user failed to validate -- Unknown Error"; e.InvalidCredentials = true; break; case AuthenticateCardUserResult.InvalidUserName: warning = "Card user not recognized"; e.InvalidCredentials = true; break; case AuthenticateCardUserResult.InvalidPin: { if (pinCounter > 1) { information = string.Format("Invalid PIN number.\n\rThere are {0} remaining tries until the card is locked out.", pinCounter); } else if (pinCounter == 1) { warning = string.Format("Invalid PIN number.\n\rThere is {0} remaining try until the card is locked out.", pinCounter); } else { warning = string.Format("The card is locked out."); } e.InvalidCredentials = true; } break; } if (e.InvalidCredentials) { if (!string.IsNullOrEmpty(error)) { Messager.Caption = "Error"; Messager.ShowError(sender as Form, error); } else if (!string.IsNullOrEmpty(warning)) { Messager.Caption = "Warning"; Messager.ShowWarning(sender as Form, warning); } else if (!string.IsNullOrEmpty(information)) { Messager.Caption = "Information"; Messager.ShowInformation(sender as Form, information); } } return(true); }