Package com.norconex.commons.lang.security

# Class Credentials

java.lang.Object
com.norconex.commons.lang.security.Credentials

All Implemented Interfaces:
  `Serializable`

public class Credentials extends Object implements Serializable

User credentials with an optionally encrypted password. To be encrypted, there needs to be an encryption key. Without one, the password is assumed not to be encrypted.

## Password encryption:

Passwords can be encrypted using `EncryptionUtil` (or command-line "encrypt.bat" or "encrypt.sh" if those are available to you). In order for the password to be decrypted properly, you need to specify the encryption key used to encrypt it. The key can obtained from a few supported locations. The combination of the password key "value" and "source" is used to properly locate the key. The supported sources are:

List of sources and their descriptions
`key` | The actual encryption key.
`file` | Path to a file containing the encryption key.
`environment` | Name of an environment variable containing the key.
`property` | Name of a JVM system property containing the key.

Since:
  2.0.0
See Also:
  - `EncryptionKey`
  - `EncryptionUtil`
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Credentials()`
  `Credentials(Credentials copy)`
  `Credentials(String username, String password)`
  Creates a new Credentials instance with the supplied username and password.
  `Credentials(String username, String password, EncryptionKey passwordKey)`
  Creates a new Credentials instance with the supplied username, password and password key.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected boolean`
  `canEqual(Object other)`
  `void`
  `copyFrom(Credentials creds)`
  `void`
  `copyTo(Credentials creds)`
  `boolean`
  `equals(Object o)`
  `String`
  `getPassword()`
  Credential password.
  `EncryptionKey`
  `getPasswordKey()`
  Credential password encryption key pointer (provided the password is encrypted).
  `String`
  `getUsername()`
  Credential user name.
  `int`
  `hashCode()`
  `boolean`
  `isEmpty()`
  `boolean`
  `isSet()`
  Whether this credentials instance is set.
  `Credentials`
  `setPassword(String password)`
  Credential password.
  `Credentials`
  `setPasswordKey(EncryptionKey passwordKey)`
  Credential password encryption key pointer (provided the password is encrypted).
  `Credentials`
  `setUsername(String username)`
  Credential user name.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### Credentials

    public Credentials()

  - ### Credentials

    public Credentials(String username, String password)
    Creates a new Credentials instance with the supplied username and password.
    Parameters:
      `username` - the username
      `password` - the password
    Since:
      3.0.0

  - ### Credentials

    public Credentials(String username, String password, EncryptionKey passwordKey)
    Creates a new Credentials instance with the supplied username, password and password key.
    Parameters:
      `username` - the username
      `password` - the password
      `passwordKey` - the password encryption key
    Since:
      3.0.0

  - ### Credentials

    public Credentials(Credentials copy)

- ## Method Details

  - ### isSet

    public boolean isSet()
    Whether this credentials instance is set. That is, if any of user name and password is not blank.
    Returns:
      `true` if set

  - ### isEmpty

    public boolean isEmpty()

  - ### copyTo

    public void copyTo(Credentials creds)

  - ### copyFrom

    public void copyFrom(Credentials creds)

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### getUsername

    public String getUsername()
    Credential user name.

  - ### getPassword

    public String getPassword()
    Credential password.

  - ### getPasswordKey

    public EncryptionKey getPasswordKey()
    Credential password encryption key pointer (provided the password is encrypted).

  - ### setUsername

    public Credentials setUsername(String username)
    Credential user name.
    Returns:
      `this`.

  - ### setPassword

    public Credentials setPassword(String password)
    Credential password.
    Returns:
      `this`.

  - ### setPasswordKey

    public Credentials setPasswordKey(EncryptionKey passwordKey)
    Credential password encryption key pointer (provided the password is encrypted).
    Returns:
      `this`.

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### canEqual

    protected boolean canEqual(Object other)

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`