/** Return the password associated with the given principal's user name. */
  protected String getPassword(String username) {

    GenericPrincipal principal = (GenericPrincipal) principals.get(username);
    if (principal != null) {
      return (principal.getPassword());
    } else {
      return (null);
    }
  }
  /**
   * Return the Principal associated with the specified username and credentials, if there is one;
   * otherwise return <code>null</code>.
   *
   * @param username Username of the Principal to look up
   * @param credentials Password or other credentials to use in authenticating this username
   */
  public Principal authenticate(String username, String credentials) {

    GenericPrincipal principal = (GenericPrincipal) principals.get(username);

    boolean validated = false;
    if (principal != null) {
      if (hasMessageDigest()) {
        // Hex hashes should be compared case-insensitive
        validated = (digest(credentials).equalsIgnoreCase(principal.getPassword()));
      } else {
        validated = (digest(credentials).equals(principal.getPassword()));
      }
    }

    if (validated) {
      if (debug >= 2) log(sm.getString("memoryRealm.authenticateSuccess", username));
      return (principal);
    } else {
      if (debug >= 2) log(sm.getString("memoryRealm.authenticateFailure", username));
      return (null);
    }
  }